homelab/roles/postgresql/tasks/main.yml

44 lines
1.0 KiB
YAML

- name: Install PostgreSQL
ansible.builtin.apt:
name: postgresql
state: present
- name: Trust connections to PostgreSQL
community.general.postgresql_pg_hba:
dest: "{{ postgresql_config }}"
contype: host
databases: all
users: all
address: "{{ item }}"
method: trust
register: postgresql_hba
loop: "{{ postgresql_trust }}"
- name: Change PostgreSQL listen addresses
community.general.postgresql_set:
name: listen_addresses
value: "{{ postgresql_listen }}"
become: true
become_user: postgres
register: postgresql_config
- name: Reload PostgreSQL
ansible.builtin.service:
name: postgresql
state: reloaded
when: postgresql_hba.changed and not postgresql_config.changed
- name: Restart PostgreSQL
ansible.builtin.service:
name: postgresql
state: restarted
when: postgresql_config.changed
- name: Allow database connections
community.general.ufw:
rule: allow
port: "5432"
proto: tcp
src: "{{ item }}"
loop: "{{ postgresql_trust }}"