Repository navigation
Expand file tree
/
Copy pathnginx_controller_postgresql_install.yaml
More file actions
179 lines (155 loc) · 4.03 KB
/
Copy pathnginx_controller_postgresql_install.yaml
File metadata and controls
179 lines (155 loc) · 4.03 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
---
# this was developed against Ubuntu 18.04
# ansible-playbook nginx_controller_postgresql_install.yaml -i dbserver -e "db_password=mySecureString"
- hosts: dbserver
remote_user: ubuntu
become: true
become_method: sudo
tasks:
- name: "Working around apt bug"
apt:
name: aptitude
state: latest
update_cache: yes
- name: "Ensure bash, OpenSSl, and libssl are the latest versions"
apt:
name: "{{ packages }}"
state: present
update_cache: yes
vars:
packages:
- bash
- openssl
- libssl-dev
- libssl-doc
- python-apt
- libpq-dev
- python-psycopg2
tags: packages
- name: "add postgresql apt-key"
apt_key:
url: "https://www.postgresql.org/media/keys/ACCC4CF8.asc"
state: present
- name: "add postgresql repository"
apt_repository:
repo: "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main"
state: present
filename: postgresql
update_cache: yes
# - name: "add postgresql repository"
# apt_repository:
# repo: "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main"
# state: present
# filename: postgresql
# update_cache: yes
- name: "Working around locale issue"
apt:
name: language-pack-en
state: present
- name: "ensure locale exists"
locale_gen:
name: en_US.UTF-8
state: present
- name: Install PostgreSQL
apt:
name: "{{ packages }}"
state: present
update_cache: yes
vars:
packages:
- postgresql-12
- postgresql-contrib-12
# - postgresql-9.5
# - postgresql-contrib-9.5
tags: packages
- name: Ensure the PostgreSQL service is running
service:
name: postgresql
state: started
enabled: yes
- name: wait a minute for PostgreSQL to get running
pause:
seconds: 30
- name: test postgresql version
become: true
become_user: postgres
postgresql_query:
db: postgres
query: SELECT version()
register: postgre
until: (postgre is defined)
retries: 5
delay: 2
- set_fact:
postgrever: "{{postgre.query_result}}"
- debug:
var: postgrever[0].version
- name: Ensure database is created
become: true
become_user: postgres
postgresql_db:
name: naas
encoding: UTF-8
lc_collate: en_US.UTF-8
lc_ctype: en_US.UTF-8
template: template0
state: present
- name: Ensure user has access to the database
become: true
become_user: postgres
postgresql_user:
db: naas
name: naas
password: "{{ db_password }}" # issue with special characters being passed
priv: ALL
state: present
- name: Ensure user does not have unnecessary privileges
become: true
become_user: postgres
postgresql_user:
name: naas
role_attr_flags: NOSUPERUSER,CREATEDB
state: present
- name: find pg_hba.conf
become: true
become_user: postgres
postgresql_query:
db: postgres
query: SHOW hba_file
register: hba
until: (hba is defined)
retries: 5
delay: 2
- name: find postgresql.conf
become: true
become_user: postgres
postgresql_query:
db: postgres
query: SHOW config_file
register: pgconf
until: (pgconf is defined)
retries: 5
delay: 2
# /etc/postgresql/9.5/main/postgresql.conf
- name: enable access from any source
lineinfile:
dest: "{{ hba.query_result[0].hba_file }}"
line: host all all 0.0.0.0/0 md5
insertafter: EOF
state: present
- name: enable any interface
lineinfile:
dest: "{{ pgconf.query_result[0].config_file }}"
line: listen_addresses='*'
insertafter: EOF
state: present
- name: increase connection count
lineinfile:
dest: "{{ pgconf.query_result[0].config_file }}"
line: 'max_connections = 200'
regexp: 'max_connections'
state: present
- name: restart postgresql
service:
name: postgresql
state: restarted