61 lines
1.7 KiB
YAML
61 lines
1.7 KiB
YAML
# vim: ft=yaml.ansible
|
|
# code: language=ansible
|
|
---
|
|
- 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
|
|
community.general.ini_file:
|
|
path: /etc/dnf/modules.d/postgresql.module
|
|
section: postgresql
|
|
option: state
|
|
value: disabled
|
|
no_extra_spaces: true
|
|
create: false
|
|
state: present
|
|
|
|
- name: Install PostgreSQL {{ postgresql_version }}
|
|
ansible.builtin.dnf:
|
|
name:
|
|
- postgresql{{ postgresql_version }}-server
|
|
- python{{ ansible_python.version.major }}-psycopg2
|
|
state: present
|
|
|
|
- name: Create PostgreSQL service override folder
|
|
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: systemd-overrides/{{ 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 folder
|
|
ansible.builtin.file:
|
|
path: "{{ postgresql_pgdata }}"
|
|
owner: root
|
|
mode: u=rwx,g=rx,o=rx
|
|
state: directory
|
|
|
|
- name: Initialize database
|
|
ansible.builtin.command:
|
|
cmd: /usr/pgsql-{{ postgresql_version }}/bin/postgresql-{{ postgresql_version }}-setup initdb
|
|
creates: "{{ postgresql_pgdata }}/base"
|
|
|
|
- name: Ensure PostgreSQL is enabled and running
|
|
ansible.builtin.service:
|
|
name: "{{ postgresql_service }}"
|
|
enabled: true
|
|
state: started
|