Files
database/roles/postgres_users/tasks/main.yml
ytshih 442e5f3d69
All checks were successful
Ansible Playbook lint & deploy / ansible-lint (push) Successful in 12s
Ansible Playbook lint & deploy / run-ansible-mongo (push) Successful in 9s
Ansible Playbook lint & deploy / run-ansible-postgres (push) Successful in 10s
Feat(pg): schema
2024-12-03 18:33:35 +00:00

32 lines
1.0 KiB
YAML

---
- name: Set username and password
ansible.builtin.set_fact:
username: "{{ postgres_users_username }}"
password: "{{ postgres_users_password }}"
database: "{{ postgres_users_database | default(postgres_users_username) }}"
schema: "{{ postgres_users_schema | default('public') }}"
- name: Create DB, role, and privs
become: true
become_user: postgres
block:
- name: Create database
community.postgresql.postgresql_db:
name: "{{ database }}"
- name: Create user
community.postgresql.postgresql_user:
db: "{{ database }}"
name: "{{ username }}"
password: "{{ password }}"
environment:
PGOPTIONS: "-c password_encryption=scram-sha-256"
- name: Configure schema
community.postgresql.postgresql_schema:
name: "{{ schema }}"
owner: "{{ username }}"
- name: Configure privileges
community.postgresql.postgresql_privs:
db: "{{ database }}"
role: "{{ username }}"
privs: ALL
objs: ALL_IN_SCHEMA