# Addionial LA pre deploy tasks

# https://github.com/AtlasOfLivingAustralia/documentation/wiki/Before-Start-Your-LA-Installation#default-user-ubuntu
- name: Add the user "{{ def_ansible_user }}"
  user: name="{{ def_ansible_user }}" shell=/bin/bash
  tags: pre-task-def-user

# https://github.com/AtlasOfLivingAustralia/documentation/wiki/SSH-for-Beginners#ssh-keys
- name: Add the ssh key to user "{{ def_ansible_user }}"
  authorized_key:
    user: "{{ def_ansible_user }}"
    state: present
    key: '{{ item }}'
  with_file: "{{ ssh_keys }}"
  tags: pre-task-ssh-keys

  # Comented for security reasons
  # - name: Add the ssh key to user 'root'
  # authorized_key:
  #   user: root
  #   state: present
  #   key: '{{ item }}'
  # with_file: "{{ ssh_keys }}"
  # tags: pre-task-ssh-keys

- name: configure byobu
  debconf:
    name: byobu
    question: byobu/launch-by-default
    value: 'True'
    vtype: boolean
  tags: pre-task-deps

- name: Add additional dependencies for monitoring, troubleshooting, ...
  apt:
    name:
      - nagios-plugins
      - python-pymongo
      - netcat
      - curl
      - lsof
      - iputils-ping
      - byobu
      - fail2ban
      - ssl-cert
      - etckeeper
    state: present
    autoclean: yes
    update_cache: yes
  tags: pre-task-deps
  when: ansible_os_family == "Debian" and ansible_distribution_version is version("20.04", "<")

- name: Add additional dependencies for monitoring, troubleshooting, ...
  apt:
    name:
      - nagios-plugins
      - python3-pymongo
      - netcat
      - curl
      - lsof
      - iputils-ping
      - byobu
      - fail2ban
      - ssl-cert
      - etckeeper
    state: present
    autoclean: yes
    update_cache: yes
  tags: pre-task-deps
  when: ansible_os_family == "Debian" and ansible_distribution_version is version("20.04", ">=") and ansible_distribution_version is version("24.04", "<")

- name: Add additional dependencies for monitoring, troubleshooting, ...
  apt:
    name:
      - nagios-plugins
      - python3-pymongo
      - netcat-openbsd
      - curl
      - lsof
      - iputils-ping
      - byobu
      - fail2ban
      - ssl-cert
      - etckeeper
    state: present
    autoclean: yes
    update_cache: yes
  tags: pre-task-deps
  when: ansible_os_family == "Debian" and ansible_distribution_version is version("24.04", ">=")


- name: copy check_mongo for nagios/icinga
  copy:
    src: files/check_mongodb.py
    dest: /usr/lib/nagios/plugins/check_mongodb
    owner: root
    group: root
    mode: 0755
  tags: pre-task-deps
