homelab/roles/postgresql/tasks/main.yml

44 lines
928 B
YAML
Raw Permalink Normal View History

2022-05-27 03:49:06 +00:00
- name: Install PostgreSQL
apt:
name: postgresql
state: present
2022-06-28 00:21:25 +00:00
- name: Trust connections to PostgreSQL
2022-05-27 03:49:06 +00:00
postgresql_pg_hba:
dest: "{{ postgresql_config }}"
contype: host
databases: all
users: all
2022-06-28 00:21:25 +00:00
address: "{{ item }}"
2022-05-27 03:49:06 +00:00
method: trust
register: postgresql_hba
2022-06-28 00:21:25 +00:00
loop: "{{ postgresql_trust }}"
2022-05-27 03:49:06 +00:00
- name: Change PostgreSQL listen addresses
postgresql_set:
name: listen_addresses
value: "{{ postgresql_listen }}"
become: true
become_user: postgres
register: postgresql_config
- name: Reload PostgreSQL
service:
name: postgresql
state: reloaded
when: postgresql_hba.changed and not postgresql_config.changed
- name: Restart PostgreSQL
service:
name: postgresql
state: restarted
when: postgresql_config.changed
2022-05-27 20:29:27 +00:00
2022-06-28 00:21:25 +00:00
- name: Allow database connections
2022-05-27 20:29:27 +00:00
ufw:
rule: allow
port: "5432"
proto: tcp
2022-06-28 00:21:25 +00:00
src: "{{ item }}"
loop: "{{ postgresql_trust }}"