69 lines
1.7 KiB
YAML
69 lines
1.7 KiB
YAML
---
|
|
- name: install postgresql
|
|
ansible.builtin.apt:
|
|
name: "{{ item }}"
|
|
state: latest
|
|
update_cache: true
|
|
loop:
|
|
- postgresql
|
|
- postgresql-contrib
|
|
notify: restart postgresql
|
|
|
|
- name: ensure postgresql data directory is a mountpoint
|
|
ansible.builtin.command: mountpoint -q /var/lib/postgresql
|
|
register: vw_mountpoint
|
|
failed_when: false
|
|
changed_when: false
|
|
|
|
- name: stop postgresql before relocating data
|
|
ansible.builtin.systemd:
|
|
name: postgresql
|
|
state: stopped
|
|
when: vw_mountpoint.rc != 0
|
|
|
|
- name: remove default postgresql data directory
|
|
ansible.builtin.file:
|
|
path: /var/lib/postgresql/
|
|
state: absent
|
|
when: vw_mountpoint.rc != 0
|
|
|
|
- name: ensure postgres data source directory exists
|
|
ansible.builtin.file:
|
|
path: /mnt/pgsql/data
|
|
state: directory
|
|
owner: postgres
|
|
group: postgres
|
|
mode: "0755"
|
|
|
|
- name: bind mount postgres data directory
|
|
ansible.posix.mount:
|
|
path: /var/lib/postgresql
|
|
src: /mnt/pgsql/data
|
|
fstype: none
|
|
opts: bind
|
|
state: mounted
|
|
notify: restart postgresql
|
|
|
|
- name: set postgres data directory ownership
|
|
ansible.builtin.file:
|
|
path: /mnt/pgsql/data
|
|
owner: postgres
|
|
group: postgres
|
|
recurse: true
|
|
|
|
- name: configure postgres
|
|
ansible.builtin.lineinfile:
|
|
path: /etc/postgresql/17/main/postgresql.conf
|
|
regexp: "^#?listen_addresses\\s*="
|
|
line: "listen_addresses = '*'"
|
|
state: present
|
|
notify: restart postgresql
|
|
|
|
- name: configure pg_hba
|
|
ansible.builtin.lineinfile:
|
|
path: /etc/postgresql/17/main/pg_hba.conf
|
|
line: "host all all {{ hostvars[item].ip }}/32 scram-sha-256"
|
|
state: present
|
|
loop: "{{ db_clients | default([]) }}"
|
|
notify: restart postgresql
|