---

# On RHEL8, enable nginx 1.20 module
- name: Enable nginx 1.20 module
  command: dnf -y module enable nginx:1.20
  when: ansible_os_family == 'RedHat' and ansible_distribution_major_version is version('8', '=')
  tags: wapt

- name: Install packages
  yum: name={{ wapt_packages }}
  tags: wapt

- name: Create SSL directory
  file: path=/var/www/html/ssl state=directory mode=750 owner=wapt group=nginx
  tags: wapt

- name: Create an empty license file
  file: path=/var/www/html/licences.json state=touch mode=644 owner=wapt
  changed_when: False
  tags: wapt

- name: Create unit snippet dir
  file: path=/etc/systemd/system/waptserver.service.d state=directory
  tags: wapt

- name: Tune wapt to restart indefinitely
  copy:
    content: |
      [Service]
      Restart=on-failure
      StartLimitInterval=0
      RestartSec=20
    dest: /etc/systemd/system/waptserver.service.d/restart.conf
  register: wapt_unit
  tags: wapt

- name: Reload systemd
  systemd: daemon_reload=True
  when: wapt_unit.changed
  tags: wapt

- name: Deploy pre and post backup scripts
  template: src={{ item }}-backup.sh.j2 dest=/etc/backup/{{ item }}.d/wapt.sh mode=0700
  with_items:
    - pre
    - post
  tags: wapt

- name: Copy setup script
  copy: src=setup.py dest=/opt/wapt/bin/setup.py mode=755
  tags: wapt

- name: Run setup script
  command: /opt/wapt/bin/setup.py
  tags: wapt
