100 lines
2.7 KiB
YAML
100 lines
2.7 KiB
YAML
# vim: ft=yaml.ansible
|
|
# code: language=ansible
|
|
---
|
|
- name: Import RPM key for PostgreSQL repository
|
|
ansible.builtin.rpm_key:
|
|
key: https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG
|
|
state: present
|
|
|
|
- name: Add PostgreSQL repository
|
|
ansible.builtin.dnf:
|
|
name: https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
|
|
state: present
|
|
|
|
- name: Disable built-in PostgreSQL module
|
|
ansible.builtin.command:
|
|
cmd: dnf -qy module disable postgresql
|
|
creates: /etc/dnf/modules.d/postgresql.module
|
|
|
|
- name: Install PostgreSQL {{ postgresql_version }}
|
|
ansible.builtin.dnf:
|
|
name:
|
|
- postgresql{{ postgresql_version }}-server
|
|
- python{{ ansible_python.version.major }}-psycopg2
|
|
update_cache: true
|
|
state: present
|
|
|
|
- name: Create PostgreSQL service override directory
|
|
ansible.builtin.file:
|
|
path: /etc/systemd/system/{{ postgresql_service }}.service.d
|
|
owner: root
|
|
mode: u=rwx,g=rx,o=rx
|
|
state: directory
|
|
|
|
- name: Copy PostgreSQL service override file
|
|
ansible.builtin.template:
|
|
src: "{{ postgresql_service }}.service.j2"
|
|
dest: /etc/systemd/system/{{ postgresql_service }}.service.d/override.conf
|
|
owner: root
|
|
mode: u=rw,g=r,o=r
|
|
notify: Reload systemd
|
|
|
|
- name: Flush handlers
|
|
ansible.builtin.meta: flush_handlers
|
|
|
|
- name: Create PGDATA directory
|
|
ansible.builtin.file:
|
|
path: "{{ postgresql_pgdata }}"
|
|
owner: postgres
|
|
mode: u=rwx,go=
|
|
state: directory
|
|
|
|
- name: Create WAL archive directory
|
|
ansible.builtin.file:
|
|
path: "{{ postgresql_wal_archive }}"
|
|
owner: postgres
|
|
mode: u=rwx,go=
|
|
state: directory
|
|
|
|
- name: Initialize database
|
|
ansible.builtin.command:
|
|
cmd: /usr/pgsql-{{ postgresql_version }}/bin/postgresql-{{ postgresql_version }}-setup initdb
|
|
creates: "{{ postgresql_pgdata }}/base"
|
|
|
|
- name: Copy postgresql.conf
|
|
ansible.builtin.template:
|
|
src: postgresql.conf.j2
|
|
dest: "{{ postgresql_pgdata }}/postgresql.conf"
|
|
owner: postgres
|
|
mode: u=rw,go=
|
|
notify: Reload PostgreSQL
|
|
|
|
- name: Copy pg_hba.conf
|
|
ansible.builtin.template:
|
|
src: pg_hba.conf.j2
|
|
dest: "{{ postgresql_pgdata }}/pg_hba.conf"
|
|
owner: postgres
|
|
mode: u=rw,go=
|
|
notify: Reload PostgreSQL
|
|
|
|
- name: Flush handlers
|
|
ansible.builtin.meta: flush_handlers
|
|
|
|
- name: Ensure PostgreSQL is enabled and running
|
|
ansible.builtin.service:
|
|
name: "{{ postgresql_service }}"
|
|
enabled: true
|
|
state: started
|
|
|
|
- name: Set up databases
|
|
ansible.builtin.include_tasks:
|
|
file: database.yml
|
|
apply:
|
|
become: true
|
|
become_user: postgres
|
|
vars:
|
|
db_name: "{{ item.key }}"
|
|
db_vars: "{{ item.value }}"
|
|
loop: "{{ databases | dict2items }}"
|
|
no_log: true
|