2024-02-16 21:04:01 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
- name: Check params
|
|
|
|
ansible.builtin.assert:
|
|
|
|
that:
|
2024-02-17 11:00:06 +02:00
|
|
|
- user is defined
|
|
|
|
- database is defined
|
|
|
|
- not(access_host is defined and password is not defined)
|
2024-02-16 21:04:01 +02:00
|
|
|
|
|
|
|
- name: Set up PostgreSQL
|
|
|
|
ansible.builtin.include_role:
|
|
|
|
name: postgresql-server
|
|
|
|
|
|
|
|
- name: Create user
|
|
|
|
community.postgresql.postgresql_user:
|
2024-02-17 11:00:06 +02:00
|
|
|
name: "{{ user }}"
|
|
|
|
password: "{{ password | default(omit) }}"
|
2024-02-16 21:04:01 +02:00
|
|
|
become: true
|
|
|
|
become_user: postgres
|
|
|
|
|
2024-02-17 11:00:06 +02:00
|
|
|
- name: Create database
|
2024-02-16 21:04:01 +02:00
|
|
|
community.postgresql.postgresql_db:
|
2024-02-17 11:00:06 +02:00
|
|
|
name: "{{ database }}"
|
|
|
|
owner: "{{ user }}"
|
2024-02-16 21:04:01 +02:00
|
|
|
become: true
|
|
|
|
become_user: postgres
|
|
|
|
|
2024-02-17 11:00:06 +02:00
|
|
|
- name: Get pg_hba.conf location
|
|
|
|
community.postgresql.postgresql_query:
|
|
|
|
query: SHOW hba_file
|
|
|
|
become: true
|
|
|
|
become_user: postgres
|
|
|
|
register: postgres_hba_file_query
|
|
|
|
|
|
|
|
- name: Update pg_hba scram authentication
|
2024-02-16 21:04:01 +02:00
|
|
|
community.postgresql.postgresql_pg_hba:
|
|
|
|
contype: host
|
2024-02-17 11:00:06 +02:00
|
|
|
users: "{{ user }}"
|
|
|
|
source: "{{ access_host }}"
|
|
|
|
databases: "{{ database }}"
|
2024-02-16 21:04:01 +02:00
|
|
|
method: "scram-sha-256"
|
2024-02-17 11:00:06 +02:00
|
|
|
dest: "{{ postgres_hba_file_query.query_result[0].hba_file }}"
|
|
|
|
when: access_host is defined
|
2024-02-16 21:04:01 +02:00
|
|
|
notify: Restart PostgreSQL
|