-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovision_database_tier.yml
85 lines (70 loc) · 2.63 KB
/
provision_database_tier.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
- name: Deploy, configure, and populate Postgres 10
hosts: database_servers
become: true
gather_facts: false
tags:
- database_servers
tasks:
- name: Install Postgres packages
package:
name: "{{ __package }}"
state: present
loop:
- "{{ postgres_rhel7_repo }}"
- "{{ postgres_packages }}"
- "{{ postgres_library }}"
loop_control:
loop_var: __package
- name: Check if Postgres initialized
stat:
path: "{{ postgres_10_data_dir }}/PG_VERSION"
register: r_postgres_init_dir_state
- when: not r_postgres_init_dir_state.stat.exists
name: Run Postgres initdb to initialize if postgres not initialized
command: "{{ postgres_10_bin_path }}/postgresql-10-setup initdb"
notify: restart_postgres
- name: Setup Postgres for remote password auth
template:
src: templates/pg_hba.conf.j2
dest: "{{ postgres_10_data_dir }}/pg_hba.conf"
notify: restart_postgres
- name: Setup Postgres to listen on network interfaces
lineinfile:
dest: "{{ postgres_10_data_dir }}/postgresql.conf"
line: "listen_addresses = '*'"
insertafter: "#listen_addresses"
notify: restart_postgres
- name: Setup Postgres as started and enabled on boot.
service:
name: "{{ postgres_service }}"
state: "{{ postgres_service_state | default('started') }}"
enabled: "{{ postgres_service_enabled | default(true) }}"
- name: Configure Postgres resources, user, database etc
block:
- name: Setup Postgres database(s)
postgresql_db:
name: "{{ __database.name }}"
state: "{{ __database.state | default('present') }}"
loop: "{{ postgres_databases }}"
loop_control:
loop_var: __database
- name: Create Postgres user#(s)
postgresql_user:
name: "{{ __user.name }}"
password: "{{ __user.password | default(omit) }}"
encrypted: true # "{{ __user.encrypted | default(omit) }}"
priv: "{{ __user.priv | default(omit) }}"
db: "{{ __user.database | default(omit) }}"
# role_attr_flags: "{{ __user.role_attr_flags | default(omit) }}"
state: "{{ __user.state | default('present') }}"
loop: "{{ postgres_users }}"
loop_control:
loop_var: __user
no_log: "{{ postgres_user_no_log_state | default(false) }}"
become_user: "{{ postgres_user }}"
handlers:
- name: restart_postgres
service:
name: "{{ postgres_service }}"
state: restarted