# pgapt
- name: Install pgdg Apt key
  apt_key:
    data: "{{ lookup('file', 'postgresql/ACCC4CF8.asc') }}"
    id: ACCC4CF8
    state: present

- name: Setup pgdg repository
  apt_repository:
    repo: 'deb http://apt.postgresql.org/pub/repos/apt/ {{ ansible_distribution_release }}-pgdg main'
    filename: 'pgdg'
    update_cache: false

- name: Setup backports repository for OmniDB
  apt_repository:
    repo: 'deb http://deb.debian.org/debian {{ ansible_distribution_release }}-backports main'
    filename: 'backports'
    update_cache: false
  when: ansible_distribution_release == "buster"

  # We want to add the debian security repository, if not already
  # present. This is required if some 3rd party package depends on
  # versions that are not included in buster main but in
  # buster/updates main.  We use lineinfile instead of apt_repository
  # to not add it if its already configured in
  # /etc/apt/sources.list. apt_repository would add a new entry within
  # /etc/apt/sources.list.d.
- name: Setup debian security repository if not already present.
  lineinfile:
    dest: /etc/apt/sources.list
    regexp: "^deb\ .*security.debian.org.*"
    line: "deb http://security.debian.org/debian-security {{ ansible_distribution_release }}/updates main contrib"
  when: ansible_distribution_release == "buster"

- name: Setup debian security repository if not already present.
  lineinfile:
    dest: /etc/apt/sources.list
    regexp: "^deb\ .*security.debian.org.*"
    line: "deb http://security.debian.org/debian-security {{ ansible_distribution_release }}-security main contrib"
  when: ansible_distribution_release != "buster" and ansible_distribution != "Ubuntu"

# apt
- name: Apt Dist-Upgrade
  apt:
    update_cache: yes
    upgrade: dist

# packages
- name: Install base packages
  package:
    name: "{{ item }}"
    state: present
  with_items:
  - tree
  - vim
  - screen
  - tmux
  - htop
  - unzip
  - w3m
  - openssh-server
  - ncdu
  - ssl-cert
  - net-tools
  - ferm

- name: Install Django for OmniDB
  package:
    name: python3-django
    state: present
    default_release: buster-backports
  when: ansible_distribution_release == "buster"

# elephant shed
# separate tasks, so we can see the progress better
- name:               Install elephant-shed-omnidb
  package: state=present name=elephant-shed-omnidb
  when: 'ansible_distribution_release != "stretch"'
- name:               Install elephant-shed-portal
  package: state=present name=elephant-shed-portal
- name:               Install elephant-shed-cockpit
  package: state=present name=elephant-shed-cockpit
- name:               Install elephant-shed-prometheus
  package: state=present name=elephant-shed-prometheus
- name:               Install elephant-shed-grafana
  package: state=present name=elephant-shed-grafana
- name:               Install elephant-shed-pgbackrest
  package: state=present name=elephant-shed-pgbackrest
- name:               Install elephant-shed-pgbadger
  package: state=present name=elephant-shed-pgbadger
- name:               Install elephant-shed-tmate
  package: state=present name=elephant-shed-tmate
- name:               Install elephant-shed-powa
  package: state=present name=elephant-shed-powa
- name:               Install elephant-shed
  package: state=present name=elephant-shed
