44 lines
1.5 KiB
YAML
44 lines
1.5 KiB
YAML
---
|
|
- name: Display Message when variables not defined
|
|
debug:
|
|
msg: "Please define postgresql_database, postgresql_username AND postgresql_password and none of them empty"
|
|
when: postgresql_database is not defined or postgresql_database == "" or postgresql_username is not defined or postgresql_username == "" or postgresql_password is not defined or postgresql_password == ""
|
|
|
|
- name: Check for variables
|
|
ansible.builtin.command: /bin/false
|
|
when: postgresql_database is not defined or postgresql_database == "" or postgresql_username is not defined or postgresql_username == "" or postgresql_password is not defined or postgresql_password == ""
|
|
|
|
- name: Install postgresql and ansible-dependencies
|
|
apt:
|
|
name:
|
|
- postgresql
|
|
- python3-psycopg2
|
|
- acl
|
|
update_cache: yes
|
|
|
|
- name: Create database
|
|
community.postgresql.postgresql_db:
|
|
name: "{{ postgresql_database }}"
|
|
encoding: UTF-8
|
|
lc_collate: C
|
|
lc_ctype: C
|
|
template: template0
|
|
become_user: postgres
|
|
|
|
- name: create database user
|
|
community.postgresql.postgresql_user:
|
|
db: "{{ postgresql_database }}"
|
|
name: "{{ postgresql_username }}"
|
|
password: "{{ postgresql_password }}"
|
|
expires: infinity
|
|
become_user: postgres
|
|
|
|
- name: Grant all privs to user to database
|
|
community.postgresql.postgresql_privs:
|
|
db: "{{ postgresql_database }}"
|
|
privs: ALL
|
|
type: database
|
|
obj: "{{ postgresql_database }}"
|
|
role: "{{ postgresql_username }}"
|
|
become_user: postgres
|