- name: install backuppc
  become: yes
  package:
    name: backuppc
    state: present

# TODO try to stop web UI from writing hosts and config.pl through file permissions
# 440 /etc/backuppc/*{pl,conf}
# 555 /etc/backuppc/

#- name: compile list of single line config values
#  set_fact:
#    single_line_conf: "{{
#        single_line_strings | wrap_list_elements("'")
#        +
#        single_line_ints
#    }}"
#  changed_when: false

- include_vars: default_excludes.yml

- name: set backuppc config options
  become: yes
  lineinfile:
    path: /etc/backuppc/config.pl
    line: "$Conf{{ '{' }}{{ item.key }}} = {{ item.value }};"
    regex: "^\\$Conf{{ '{' }}{{ item.key }}} ="
  loop: "{{ single_line_conf | dict2items }}"

- include_tasks: ensure_marker.yml
  loop: "{{ multi_line_conf.keys() | list }}"
  loop_control:
    loop_var: option

- name: create block
  become: yes
  blockinfile:
    block: "{{ \"$Conf{\" + item.key + \"} =\" + item.value }}"
    marker: "### {mark} ANSIBLE MANAGED {{ item.key }} ###"
    insertafter: "^temporary marker for '{{ item.key }}'$"
    path: /etc/backuppc/config.pl
  loop: "{{ multi_line_conf | dict2items }}"

- include_role: name=quadrant_backuppc_server_config
