first version of ansible role for postgresql
This commit is contained in:
1 parent
35b54737ce
commit
7aaab1e4b0
2 files changed
+53
-1
No files matched your search
@@ -0,0 +1,42 @@
|
||||
---
|
||||
- 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
|
||||
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
|
||||
Reference in new issue
Block a user