postgresql role continuation

This commit is contained in:
Sam A. 2023-11-12 20:22:32 +01:00
parent f09fbdefef
commit 7885de776c
Signed by: samsapti
GPG key ID: CBBBE7371E81C4EA
4 changed files with 50 additions and 2 deletions

View file

@ -2,5 +2,6 @@
# code: language=ansible # code: language=ansible
--- ---
postgresql_version: 14 postgresql_version: 14
postgresql_pgdata: /var/lib/pgsql/{{ postgresql_version }}/data postgresql_pgdata_default: /var/lib/pgsql/{{ postgresql_version }}/data
postgresql_pgdata: "{{ postgresql_pgdata_default }}"
postgresql_service: postgresql-{{ postgresql_version }} postgresql_service: postgresql-{{ postgresql_version }}

View file

@ -0,0 +1,6 @@
# vim: ft=yaml.ansible
# code: language=ansible
---
- name: Reload systemd
ansible.builtin.systemd:
daemon_reload: true

View file

@ -18,5 +18,43 @@
- name: Install PostgreSQL {{ postgresql_version }} - name: Install PostgreSQL {{ postgresql_version }}
ansible.builtin.dnf: ansible.builtin.dnf:
name: postgresql{{ postgresql_version }}-server name:
- postgresql{{ postgresql_version }}-server
- python{{ ansible_python.version.major }}-psycopg2
state: present 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: 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
when: postgresql_pgdata != postgresql_pgdata_default
notify: Reload systemd
- name: Flush handlers
ansible.builtin.meta: flush_handlers
- name: Check if pgdata directory is initialized
ansible.builtin.stat:
path: "{{ postgresql_pgdata }}/base"
register: pgdata_stat
failed_when: false
- name: Initialize database
ansible.builtin.command:
cmd: /usr/pgsql-{{ postgresql_version }}/bin/postgresql-{{ postgresql_version }}-setup initdb
when: pgdata_stat.stat.isdir is not defined or not pgdata_stat.stat.isdir
- name: Ensure PostgreSQL is enabled and running
ansible.builtin.service:
name: "{{ postgresql_service }}"
enabled: true
state: started

View file

@ -0,0 +1,3 @@
# code: language=ansible-jinja
[Service]
Environment=PGDATA={{ postgresql_pgdata }}