An Ansible role to create a PostgreSQL database and user.
It can be executed on any node, not especially the one where the application using the DB will be used, as the role connects to the cluster to create the database and user.
Requires:
-
community.postgresqlAnsible collection -
psycopg2-binaryPython library to be installedIt can be installed using the
geerlingguy.pipAnsible role for example.
cluster_host: PostgreSQL cluster hostcluster_admin_user: PostgreSQL cluster admin usercluster_admin_password: PostgreSQL cluster admin passwordapp_db_user: Application database userapp_db_password: Application database passwordapp_db_name: Application database name
None
---
- name: Tests
hosts: tests
roles:
- role: bastantoine.pg-database
vars:
cluster_host: db.example.com
cluster_admin_user: "admin"
cluster_admin_password: "{{ admin_password }}"
app_db_name: "db"
app_db_user: "user"
app_db_password: "{{ user_password }}"MIT