- name: compile list of hosts using quadrant_backup
  set_fact:
    quadrant_backup_clients: "{{ hosts | map_dict_values_to_subkey('quadrant_backup') | sort_dict_by_keys }}"
  changed_when: False

# read vars from basic installation role
- include_vars: roles/quadrant_backuppc_deploy/vars/default_excludes.yml

- name: backuppc ssh config
  become: yes
  template:
    src: ssh_config.j2
    dest: /var/lib/backuppc/.ssh/config
    owner: backuppc
    group: backuppc
    mode: 0660

- name: backuppc hosts
  become: yes
  template:
    src: backuppc_hosts.j2
    dest: /etc/backuppc/hosts
  vars:
    clients: "{{ quadrant_backup_clients.keys() | list }}"
  # no notify needed: backuppc reloads at every wakeup

- name: backuppc client config
  become: yes
  template:
    # use fixed template (example: windows) or generated template
    src: "{{ item.key + '.j2' if (item.value.get_config_from_template | default(false)) else 'client.j2' }}"
    dest: /etc/backuppc/{{item.key}}.pl
    owner: backuppc
    group: www-data
    mode: 0640
  with_items: "{{ quadrant_backup_clients | dict2items }}"
  when: item.value.backuppc_client_conf is defined or item.value.BackupExcludes is defined or (item.value.DisableBackupExcludeDefaults | default(False)) or item.value.database_backup is defined or (item.value.get_config_from_template | default (False)) is defined

- name: create /etc/hosts with hosts who have quadrant_backup.ip
  become: yes
  template:
    src: hosts.j2
    dest: /etc/hosts
    mode: 0644
