homelab/roles/postgresql/tasks/main.yml

44 lines
1.0 KiB
YAML
Raw Normal View History

2022-05-27 03:49:06 +00:00
- name: Install PostgreSQL
2023-05-04 03:42:55 +00:00
ansible.builtin.apt:
2022-05-27 03:49:06 +00:00
name: postgresql
state: present
2022-06-28 00:21:25 +00:00
- name: Trust connections to PostgreSQL
2023-05-04 03:42:55 +00:00
community.general.postgresql_pg_hba:
2022-05-27 03:49:06 +00:00
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
2023-05-04 03:42:55 +00:00
community.general.postgresql_set:
2022-05-27 03:49:06 +00:00
name: listen_addresses
value: "{{ postgresql_listen }}"
become: true
become_user: postgres
register: postgresql_config
- name: Reload PostgreSQL
2023-05-04 03:42:55 +00:00
ansible.builtin.service:
2022-05-27 03:49:06 +00:00
name: postgresql
state: reloaded
when: postgresql_hba.changed and not postgresql_config.changed
- name: Restart PostgreSQL
2023-05-04 03:42:55 +00:00
ansible.builtin.service:
2022-05-27 03:49:06 +00:00
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
2023-05-04 03:42:55 +00:00
community.general.ufw:
2022-05-27 20:29:27 +00:00
rule: allow
port: "5432"
proto: tcp
2022-06-28 00:21:25 +00:00
src: "{{ item }}"
loop: "{{ postgresql_trust }}"