---

- name: Create mandatory directories
  file:
    path: "{{ item }}"
    state: directory
  with_items:
    - "{{ haproxy_cert_path }}"
    - "{{ haproxy_template_path }}"
    - "{{ haproxy_config_path }}"

- name: create haproxy template config files
  template:
    src: "haproxy/config/{{ item }}"
    dest: "{{ haproxy_template_path }}/{{ item }}"
    variable_start_string: "€#"
    variable_end_string: "#€"
    block_start_string: "€%"
    block_end_string: "%€"
  with_items:
    - haproxy.cfg
    - haproxy.cfg.tmpl
    - allCerts.tmpl
    - haproxy-userlist.cfg.tmpl
    - haproxy-userlist.cfg
    - consul-template-haproxy.service
    - consul-template-haproxy-ssl.service
    - consul-template-haproxy-userlist.service

- name: copy haproxy service systemd
  template:
    src: haproxy/haproxy.service
    dest: /etc/systemd/system/haproxy.service

- name: Create haproxy-reload script
  template:
    src: haproxy/haproxy-reload.sh
    dest: "{{ local_bin_path }}/haproxy_reload"
    mode: 0755

- name: Create haproxy-cert-reload script
  template:
    src: haproxy/haproxy-certs-reload.sh
    dest: "{{ local_bin_path }}/haproxy_certs_reload"
    mode: 0755
