ansible/roles/postgresql_server/tasks/main.yml
Mikolaj Izdebski 8da3e395b2 postgresql: Install mbuffer package
mbuffer is required on db-koji for staging-sync playbook, but
installing it on all DB servers doesn't hurt.
2025-07-04 19:44:32 +02:00

161 lines
4.6 KiB
YAML

---
#
# Setup postgresql server.
#
- name: On db-koji01 and db-riscv-koji01 and db01.stg and db-fas01 and db01 and db-openqa01 enable the postgresql 16 module.
ansible.builtin.copy:
dest: /etc/dnf/modules.d/postgresql.module
content: |
[postgresql]
name=postgresql
stream=16
profiles=
state=enabled
when: inventory_hostname.startswith(('db-koji01','db-riscv-koji01','db01.stg','db-fas01','db01','db-openqa01'))
- name: Install postgresql server packages (Fedora)
ansible.builtin.package:
state: present
name:
- postgresql-server
- postgresql-contrib
- postgresql-plpython3
- python3-psycopg2
- pxz
- mbuffer
when: ansible_distribution_major_version|int >= 29 and ansible_distribution == 'Fedora' and ansible_cmdline.ostree is not defined
tags:
- packages
- postgresql
- name: Install postgresql server packages (EL >= 8)
ansible.builtin.package:
state: present
name:
- postgresql-server
- postgresql-contrib
- postgresql-plpython3
- python3-psycopg2
- pxz
- mbuffer
when: ansible_distribution_major_version|int >= 8 and ansible_distribution == 'RedHat' and ansible_cmdline.ostree is not defined
tags:
- packages
- postgresql
- name: Set kernel shared memory max to a larger value
sysctl: name=kernel.shmmax value={{ kernel_shmmax }}
when: kernel_shmmax is defined
notify:
- Restart postgresql
tags:
- postgresql
- name: Initialize postgres if necessary
ansible.builtin.command: /usr/bin/postgresql-setup initdb
creates=/var/lib/pgsql/data/postgresql.conf
notify:
- Restart postgresql
tags:
- postgresql
- name: Set postgresql-server to run on boot
service: name=postgresql enabled=yes
ignore_errors: true
notify:
- Restart postgresql
tags:
- service
- postgresql
- name: Add our postgres config file.
ansible.builtin.copy: >
src={{ item }}
dest=/var/lib/pgsql/data/{{ item }}
owner=postgres
with_items:
- pg_hba.conf
notify:
- Restart postgresql
tags:
- config
- postgresql
- name: Postgresql config template (el9 / postgresql 15)
ansible.builtin.template: dest=/var/lib/pgsql/data/postgresql.conf src=postgresql.conf-15
when: (ansible_distribution_major_version|int == 9 and ansible_distribution == 'RedHat')
notify:
- Restart postgresql
tags:
- config
- postgresql
- name: Postgresql config template (el9 / postgresql 16)
ansible.builtin.template: dest=/var/lib/pgsql/data/postgresql.conf src=postgresql.conf-16
when: (ansible_distribution_major_version|int == 9 and ansible_distribution == 'RedHat')
notify:
- Restart postgresql
tags:
- config
- postgresql
- name: Ensure postgres has a place to backup to
ansible.builtin.file: dest=/backups state=directory owner=postgres
tags:
- postgresql
- name: Copy over backup scriplet
ansible.builtin.copy: src=backup-database dest=/usr/local/bin/backup-database mode=0755
when: not inventory_hostname.startswith(('db-koji01.rdu3', 'db-datanommer'))
tags:
- postgresql
# Main koji is _big_ so we don't keep multiple copies of backups, so special
# backup script. Smaller koji's are fine with the default N backups.
- name: Copy over backup scriplet
ansible.builtin.copy: src=backup-database.db-koji01 dest=/usr/local/bin/backup-database mode=0755
when: inventory_hostname.startswith('db-koji01.rdu3')
tags:
- postgresql
- name: Copy over backup scriplet
ansible.builtin.copy: src=backup-database.db-datanommer02 dest=/usr/local/bin/backup-database mode=0755
when: inventory_hostname.startswith('db-datanommer02.rdu3')
tags:
- postgresql
- name: Copy over anitya public backup scriplet
ansible.builtin.copy: src=backup-database.anitya dest=/usr/local/bin/backup-database.anitya mode=0755
tags:
- postgresql
when: inventory_hostname.startswith('db01.rdu3')
- name: Copy over anitya public backup cron
ansible.builtin.copy: src=cron-backup-anitya-public dest=/etc/cron.d/cron-backup-anitya-public mode=0644
tags:
- postgresql
when: inventory_hostname.startswith('db01.rdu3')
- name: Set up some cronjobs to backup databases as configured
ansible.builtin.template: >
src=cron-backup-database
dest=/etc/cron.d/cron-backup-database-{{ item }}
with_items:
- "{{ dbs_to_backup }}"
when: dbs_to_backup != []
tags:
- cron
- postgresql
- name: Set up datanommer/datagrepper SAR script
ansible.builtin.copy: >
src=datagrepper_sar.py
dest=/usr/local/bin/datagrepper_sar.py mode=0700
when: inventory_hostname.startswith('db-datanommer01')
tags:
- postgresql
- SAR
- GBDR
- import_tasks: datanommer.yml
when: inventory_hostname.startswith('db-datanommer')