- name: Install consul-template
  unarchive:
    src: "https://releases.hashicorp.com/consul-template/0.37.4/consul-template_0.37.4_linux_amd64.zip"
    dest: /usr/local/bin
    remote_src: yes

- name: Create consul-template directories
  file:
    path: "{{ item }}"
    state: directory
    mode: '0755'
  loop:
    - /etc/consul-template
    - /etc/ssl/certs
    - /etc/ssl/private

- name: Deploy consul-template config
  template:
    src: consul-template-config.hcl.j2
    dest: /etc/consul-template/config.hcl
    mode: '0600'

- name: Deploy consul-template systemd unit
  template:
    src: consul-template.service.j2
    dest: /etc/systemd/system/consul-template.service

- name: Enable and start consul-template
  systemd:
    name: consul-template
    enabled: true
    state: restarted
    daemon_reload: yes
