-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure_postgresql.yml
60 lines (52 loc) · 1.61 KB
/
configure_postgresql.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
---
- name: Configure PostgreSQL
block:
- name: Ensure PostgreSQL is installed
apt:
name: postgresql
state: present
- name: Ensure python3-psycopg2 is installed for Ansible PostgreSQL modules
apt:
name: python3-psycopg2
state: present
- name: Ensure PostgreSQL service is started
service:
name: postgresql
state: started
- name: Check PostgreSQL service status
command: systemctl status postgresql.service
register: postgresql_status
failed_when: false
- name: Debug PostgreSQL service status
debug:
var: postgresql_status.stdout_lines
- name: Check if PostgreSQL database exists
postgresql_db:
name: "{{ db_name }}"
state: present
register: db_exists
- name: Create PostgreSQL database if it does not exist
postgresql_db:
login_user: "{{ postgres_root_user }}"
name: "{{ db_name }}"
state: present
when:
- not db_exists.changed
- name: Ensure PostgreSQL user exists
postgresql_user:
login_user: "{{ postgres_root_user }}"
name: "{{ movim_db_user }}"
password: "{{ movim_db_password }}"
db: "{{ db_name }}"
priv: "ALL"
state: present
- name: Ensure PostgreSQL database uses utf8mb4_bin collation
postgresql_db:
login_user: "{{ movim_db_user }}"
login_password: "{{ movim_db_password }}"
name: "{{ db_name }}"
encoding: "UTF8"
lc_collate: "en_US.utf8"
lc_ctype: "en_US.utf8"
state: present
when: db_type == "postgresql"