---
# file: roles/haproxy/tasks/configure.yml

- name: "Proxy | Install SSL certificates"
  copy: src={{inventory_dir}}/files/ssl/{{item.file}}
        dest=/etc/haproxy/certs
  with_items: '{{ proxy_certificates }}'
  notify: 'Proxy | Restart HAProxy'

- name: "Proxy | Create host lists"
  template: src=host_list
            dest=/etc/haproxy/{{item}}.list
            owner=root
            group=root
            mode=644
  #when: scope == 'all'
  with_items: '{{ groups.all }}'
  notify: 'Proxy | Restart HAProxy'

- name: "Proxy | Create host ssl lists"
  template: src=host_ssl_list
            dest=/etc/haproxy/{{item}}.ssl.list
            owner=root
            group=root
            mode=644
  #when: scope == 'all'
  with_items: '{{ groups.all }}'
  notify: 'Proxy | Restart HAProxy'

- name: "Proxy | Create empty crm lists files"
  file: dest=/etc/haproxy/{{item}}.crm.list
        owner=root
        group=root
        mode=644
        state=touch
  #when: scope == 'all'
  with_items: '{{ groups.all }}'
  notify: 'Proxy | Restart HAProxy'

- name: "Proxy | Create config file"
  template: src=haproxy_cfg
            dest=/etc/haproxy/haproxy.cfg
            owner=root
            group=root
            mode=644
  #when: scope == 'all'
  notify: 'Proxy | Restart HAProxy'

- name: "Proxy | Install update php script"
  copy: src=etc_haproxy_update_update_php
        dest=/etc/haproxy/update/update.php
        owner=root
        group=root
        mode=444

- name: "Proxy | Update blacklist"
  template: src=blacklist
            dest=/etc/haproxy/blacklist
            owner=root
            group=root
            mode=644
  #when: scope == 'all'
  notify: 'Proxy | Restart HAProxy'
