postgresql role continuation
This commit is contained in:
parent
f09fbdefef
commit
7885de776c
|
@ -2,5 +2,6 @@
|
|||
# code: language=ansible
|
||||
---
|
||||
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 }}
|
||||
|
|
6
roles/postgresql/handlers/main.yml
Normal file
6
roles/postgresql/handlers/main.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
# vim: ft=yaml.ansible
|
||||
# code: language=ansible
|
||||
---
|
||||
- name: Reload systemd
|
||||
ansible.builtin.systemd:
|
||||
daemon_reload: true
|
|
@ -18,5 +18,43 @@
|
|||
|
||||
- name: Install PostgreSQL {{ postgresql_version }}
|
||||
ansible.builtin.dnf:
|
||||
name: postgresql{{ postgresql_version }}-server
|
||||
name:
|
||||
- postgresql{{ postgresql_version }}-server
|
||||
- python{{ ansible_python.version.major }}-psycopg2
|
||||
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
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
# code: language=ansible-jinja
|
||||
[Service]
|
||||
Environment=PGDATA={{ postgresql_pgdata }}
|
Loading…
Reference in a new issue