---

- name: Deploy systemd service unit
  template: src=consul.service.j2 dest=/etc/systemd/system/consul.service
  register: consul_unit
  notify: restart consul
  tags: consul

- name: Install backup hooks
  template: src={{ item }}-backup.j2 dest=/etc/backup/{{ item }}.d/consul mode=700
  loop:
    - pre
    - post
  tags: consul

- name: Create tmpfiles fragment
  copy:
    content: |
      d /run/consul 770 root {{ consul_user }}
    dest: /etc/tmpfiles.d/consul.conf
  register: consul_tmpfiles
  tags: consul

- name: Create tmpfiles
  command: systemd-tmpfiles --create
  when: consul_tmpfiles.changed
  tags: consul

- name: Reload systemd
  systemd: daemon_reload=True
  when: consul_unit.changed
  tags: consul

