---

- name: Dependencies are installed
  apt:
    name:
      - sudo
      - curl
    state: present
  tags:
    - evomaintenance

- name: PG dependencies are installed
  apt:
    name:
      - postgresql-client
    state: present
  when: evomaintenance_hook_db | bool
  tags:
    - evomaintenance

- include_role:
    name: evolix/remount-usr
  tags:
    - evomaintenance

- name: /usr/share/scripts exists
  file:
    dest: /usr/share/scripts
    mode: "0700"
    owner: root
    group: root
    state: directory
  tags:
    - evomaintenance

- name: Evomaintenance script and template are installed
  copy:
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
    owner: root
    group: root
    mode: "{{ item.mode }}"
    force: yes
    backup: yes
  loop:
    - { src: 'evomaintenance.sh', dest: '/usr/share/scripts/', mode: '0700' }
    - { src: 'evomaintenance.tpl', dest: '/usr/share/scripts/', mode: '0600' }
  tags:
    - evomaintenance

- name: Configuration is installed
  template:
    src: evomaintenance.j2
    dest: /etc/evomaintenance.cf
    owner: root
    group: root
    mode: "0600"
    force: "{{ evomaintenance_force_config | bool }}"
  tags:
    - evomaintenance
