main.yml 1.41 KB
Newer Older
Robin Sonnabend's avatar
Robin Sonnabend committed
1
2
---

3
4
5
6
7
8
9
10
11
12
13
14
15
16
- when: postgres_pgdg_repo
  block:
    - name: Install pgdg apt repo key
      apt_key:
        url: https://www.postgresql.org/media/keys/ACCC4CF8.asc
        state: present
    - name: Configure pgdg apt repo
      apt_repository:
        repo: >-
          deb
          https://apt.postgresql.org/pub/repos/apt
          {{ ansible_distribution_release }}-pgdg
          main

Robin Sonnabend's avatar
Robin Sonnabend committed
17
- name: ensure postgres packages are installed
18
  apt:
Robin Sonnabend's avatar
Robin Sonnabend committed
19
    name:
20
      # yamllint disable-line rule:line-length
21
      - postgresql{{ "-{}".format(postgres_version) if postgres_version is defined }}
Robin Sonnabend's avatar
Robin Sonnabend committed
22
23
      - python3-psycopg2
      - libpq-dev
24
    state: present
Robin Sonnabend's avatar
Robin Sonnabend committed
25

26
27
28
29
30
31
32
- name: ensure legacy postgres packages are installed
  apt:
    name:
      - python-psycopg2
    state: present
  when: ansible_distribution_major_version|int(default=99) < 11

Robin Sonnabend's avatar
Robin Sonnabend committed
33
- name: ensure postgres is started
34
35
36
  service:
    name: postgresql
    state: started
Lars Beckers's avatar
Lars Beckers committed
37
    enabled: true
38
39

- name: ensure we have our postgres backup script
40
  copy:
41
42
    src: "pgbackup{{ '-bullseye' if ansible_distribution_major_version|int(default=99) > 10 else '' }}.sh"
    dest: /usr/local/bin/pgbackup.sh
43
44
    owner: root
    group: root
Lars Beckers's avatar
Lars Beckers committed
45
    mode: '0755'
46
47

- name: ensure we have our rsnapshot config
48
49
  copy:
    src: rsnapshot.conf
50
    dest: /etc/rsnapshot.d/postgres.conf
51
52
    owner: root
    group: root
Lars Beckers's avatar
Lars Beckers committed
53
    mode: '0644'
54

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