---

- name: ensure postgres packages are installed
  apt:
    name:
      - postgresql
      - python-psycopg2
      - python3-psycopg2
      - libpq-dev
    state: present
  tags:
    - postgres

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

- name: ensure we have rsnapshot
  apt:
    name: rsnapshot
    state: present
  tags:
    - postgres
    - rsnapshot
    - backup

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

- name: ensure we have our rsnapshot config
  template:
    src: rsnapshot.conf.j2
    dest: /etc/
    owner: root
    group: root
    mode: '0644'
  tags:
    - postgres
    - rsnapshot
    - backup

- name: ensure rsnapshot is running regularly
  template:
    src: crontab.j2
    dest: /etc/cron.d/postgres-snapshot
    owner: root
    group: root
    mode: '0644'
  tags:
    - postgres
    - rsnapshot
    - backup