- name: Create database user
postgresql_user:
name: "{{ database_name }}"
password: "{{ database_password }}"
become: true
become_user: postgres
- name: Create database
postgresql_db:
owner: "{{ database_name }}"
- name: Grant access to database
postgresql_privs:
type: database
database: "{{ database_name }}"
role: "{{ database_name }}"
grant_option: no
privs: all
notify: restart postgres
- name: Allow remote access to database
postgresql_pg_hba:
dest: /etc/postgresql/15/main/pg_hba.conf
contype: host
databases: "{{ database_name }}"
users: "{{ database_name }}"
address: all
create: true