main.yml 1.56 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
40
41
42
43
44
45
46
47
48
- name: configure snapshots
  when: '"servers_rsnapshot" in group_names'
  block:
    - name: ensure we have our postgres backup script
      copy:
        src: "pgbackup{{ '-bullseye' if ansible_distribution_major_version|int(default=99) > 10 else '' }}.sh"
        dest: /usr/local/bin/pgbackup.sh
        owner: root
        group: root
        mode: '0755'
49

50
51
52
53
54
55
56
    - name: ensure we have our rsnapshot config
      copy:
        src: rsnapshot.conf
        dest: /etc/rsnapshot.d/postgres.conf
        owner: root
        group: root
        mode: '0644'
57

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