---

- name: ensure postgres packages are installed
  apt:
    name:
      - postgresql{{ "-{}".format(postgres_version) if postgres_version is defined }}
      - python-psycopg2
      - python3-psycopg2
      - libpq-dev
    state: present

- name: ensure postgres is started
  service:
    name: postgresql
    state: started
    enabled: true

- name: ensure we have our postgres backup script
  copy:
    src: pgbackup.sh
    dest: /usr/local/bin/
    owner: root
    group: root
    mode: '0755'

- name: ensure we have our rsnapshot config
  copy:
    src: rsnapshot.conf
    dest: /etc/rsnapshot.d/postgres.conf
    owner: root
    group: root
    mode: '0644'

- name: remove obsolete crontab
  file:
    path: /etc/cron.d/postgres-snapshot
    state: absent
