Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/setup_postgresql_db/tasks/main.yml

raw
1 ---
2 ####################################################################
3 # WARNING: These are designed specifically for Ansible tests #
4 # and should not be used as examples of how to write Ansible roles #
5 ####################################################################
6
7 # Copyright (c) Ansible Project
8 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
9 # SPDX-License-Identifier: GPL-3.0-or-later
10
11 # Exit when Suse because it causes CI problems
12 - meta: end_play
13 when: ansible_facts.os_family == 'Suse'
14
15 # To avoid hangings on service start/stop postgres during CI runs:
16 - meta: end_play
17 when: ansible_facts.distribution == 'CentOS' and ansible_facts.distribution_major_version == '8'
18
19 # Temporary disable Fedora 34
20 - meta: end_play
21 when: ansible_facts.distribution == 'Fedora' and ansible_facts.distribution_major_version == '34'
22
23 # Temporary disable Fedora 44
24 - meta: end_play
25 when: ansible_facts.distribution == 'Fedora' and ansible_facts.distribution_major_version == '44'
26
27 - name: Include distribution and Python version specific variables
28 include_vars: '{{ lookup(''first_found'', params) }}'
29 vars:
30 params:
31 files:
32 - '{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml'
33 - '{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_version }}.yml'
34 - '{{ ansible_facts.os_family }}.yml'
35 - default.yml
36 paths:
37 - '{{ role_path }}/vars'
38
39 - name: make sure the dbus service is started under systemd
40 systemd:
41 name: dbus
42 state: started
43 when: ansible_facts.service_mgr == 'systemd' and ansible_facts.distribution == 'Fedora'
44
45 - name: Kill all postgres processes
46 shell: 'pkill -u {{ pg_user }}'
47 become: true
48 when: ansible_facts.distribution == 'CentOS' and ansible_facts.distribution_major_version == '8'
49 ignore_errors: true
50
51 - name: stop postgresql service
52 service: name={{ postgresql_service }} state=stopped
53 ignore_errors: true
54
55 - name: remove old db (RedHat or Suse)
56 file:
57 path: '{{ pg_dir }}'
58 state: absent
59 ignore_errors: true
60 when: ansible_facts.os_family == "RedHat" or ansible_facts.os_family == "Suse"
61
62 - name: remove old db (FreeBSD)
63 file:
64 path: '{{ pg_dir }}'
65 state: absent
66 ignore_errors: true
67 when: ansible_facts.os_family == "FreeBSD"
68
69 - name: remove old db config and files (debian)
70 file:
71 path: '{{ loop_item }}'
72 state: absent
73 ignore_errors: true
74 when: ansible_facts.os_family == "Debian"
75 loop:
76 - /etc/postgresql
77 - /var/lib/postgresql
78 loop_control:
79 loop_var: loop_item
80
81 - name: install dependencies for postgresql test
82 package:
83 name: '{{ postgresql_package_item }}'
84 state: present
85 with_items: '{{ postgresql_packages }}'
86 loop_control:
87 loop_var: postgresql_package_item
88
89 - name: initialize postgres (FreeBSD)
90 command: /usr/local/etc/rc.d/postgresql oneinitdb
91 when: ansible_facts.os_family == "FreeBSD"
92
93 - name: Initialize postgres (RedHat systemd)
94 command: postgresql-setup initdb
95 when: ansible_facts.os_family == "RedHat" and ansible_facts.service_mgr == "systemd"
96
97 - name: Initialize postgres (RedHat sysv)
98 command: /sbin/service postgresql initdb
99 when: ansible_facts.os_family == "RedHat" and ansible_facts.service_mgr != "systemd"
100
101 - name: Initialize postgres (Archlinux)
102 command: su - postgres -c "initdb --locale en_US.UTF-8 -D '/var/lib/postgres/data'"
103 args:
104 creates: /var/lib/postgres/data/PG_VERSION
105 when: ansible_facts.os_family == "Archlinux"
106
107 - name: Initialize postgres (Alpine)
108 command: su - postgres -c "initdb --locale en_US.UTF-8 -D '/var/lib/postgresql/data'"
109 when: ansible_facts.os_family == "Alpine"
110
111 - name: Initialize postgres (Debian)
112 shell: . /usr/share/postgresql-common/maintscripts-functions && set_system_locale && /usr/bin/pg_createcluster -u postgres {{ pg_ver }} main
113 args:
114 creates: /etc/postgresql/{{ pg_ver }}/
115 when: ansible_facts.os_family == 'Debian'
116
117 - name: Initialize postgres (Suse)
118 service: name=postgresql state=stopped
119 when: ansible_facts.os_family == 'Suse'
120
121 - name: Pause between stop and start postgresql
122 pause:
123 seconds: 5
124 when: ansible_facts.os_family == 'Suse'
125
126 - name: Make installable on Arch
127 community.general.ini_file:
128 path: /usr/lib/systemd/system/postgresql.service
129 section: Service
130 option: "{{ item }}"
131 state: absent
132 loop:
133 - PrivateTmp
134 - ProtectHome
135 - ProtectSystem
136 - NoNewPrivileges
137 - ProtectControlGroups
138 - ProtectKernelModules
139 - ProtectKernelTunables
140 - PrivateDevices
141 - RestrictAddressFamilies
142 - RestrictNamespaces
143 - RestrictRealtime
144 - SystemCallArchitectures
145 when: ansible_facts.distribution == 'Archlinux'
146
147 - name: Make installable on Arch
148 systemd:
149 daemon_reload: true
150 when: ansible_facts.distribution == 'Archlinux'
151
152 - name: Initialize postgres (Suse)
153 service: name=postgresql state=started
154 when: ansible_facts.os_family == 'Suse'
155
156 - name: Copy pg_hba into place
157 template:
158 src: files/pg_hba.conf
159 dest: '{{ pg_hba_location }}'
160 owner: '{{ pg_user }}'
161 group: '{{ pg_group }}'
162 mode: '0644'
163
164 - name: Generate locales (Debian)
165 locale_gen:
166 name: '{{ item }}'
167 state: present
168 with_items:
169 - pt_BR
170 - es_ES
171 when: ansible_facts.os_family == 'Debian'
172
173 - block:
174 - name: Install langpacks (RHEL8)
175 yum:
176 name:
177 - glibc-langpack-es
178 - glibc-langpack-pt
179 - glibc-all-langpacks
180 state: present
181 when: ansible_facts.distribution_major_version is version('8', '>=')
182
183 - name: Check if locales need to be generated (RedHat)
184 shell: localedef --list-archive | grep -a -q '^{{ locale }}$'
185 register: locale_present
186 ignore_errors: true
187 with_items:
188 - es_ES
189 - pt_BR
190 loop_control:
191 loop_var: locale
192
193 - name: Reinstall internationalization files
194 shell: yum -y reinstall glibc-common || yum -y install glibc-common
195 when: locale_present is failed
196
197 - name: Generate locale (RedHat)
198 command: localedef -f ISO-8859-1 -i {{ item.locale }} {{ item.locale }}
199 when: item is failed
200 with_items: '{{ locale_present.results }}'
201 when: ansible_facts.os_family == 'RedHat' and ansible_facts.distribution != 'Fedora'
202
203 - name: Install glibc langpacks (Fedora >= 24)
204 package:
205 name: '{{ item }}'
206 state: latest
207 with_items:
208 - glibc-langpack-es
209 - glibc-langpack-pt
210 when: ansible_facts.distribution == 'Fedora' and ansible_facts.distribution_major_version is version('24', '>=')
211
212 - name: enable postgresql service (FreeBSD)
213 lineinfile:
214 path: /etc/rc.conf
215 line: postgresql_enable="YES"
216 when: ansible_facts.os_family == "FreeBSD"
217
218 - name: start postgresql service
219 service: name={{ postgresql_service }} state=started
220
221 - name: Pause between start and stop
222 pause:
223 seconds: 5
224
225 - name: Kill all postgres processes
226 shell: 'pkill -u {{ pg_user }}'
227 become: true
228 when: ansible_facts.distribution == 'CentOS' and ansible_facts.distribution_major_version == '8'
229 ignore_errors: true
230 register: terminate
231
232 - name: Stop postgresql service
233 service: name={{ postgresql_service }} state=stopped
234 when: terminate is not succeeded
235
236 - name: Pause between stop and start
237 pause:
238 seconds: 5
239
240 - name: Start postgresql service
241 service: name={{ postgresql_service }} state=started
242
243 - name: copy control file for dummy ext
244 copy:
245 src: dummy.control
246 dest: /usr/share/postgresql/{{ pg_ver }}/extension/dummy.control
247 mode: '0444'
248 when: ansible_facts.os_family == 'Debian'
249
250 - name: copy version files for dummy ext
251 copy:
252 src: '{{ item }}'
253 dest: /usr/share/postgresql/{{ pg_ver }}/extension/{{ item }}
254 mode: '0444'
255 with_items:
256 - dummy--1.0.sql
257 - dummy--2.0.sql
258 - dummy--3.0.sql
259 when: ansible_facts.os_family == 'Debian'
260
261 - name: add update paths
262 file:
263 path: /usr/share/postgresql/{{ pg_ver }}/extension/{{ item }}
264 mode: '0444'
265 state: touch
266 with_items:
267 - dummy--1.0--2.0.sql
268 - dummy--2.0--3.0.sql
269 when: ansible_facts.os_family == 'Debian'
270
271 - name: Get PostgreSQL version
272 become_user: '{{ pg_user }}'
273 become: true
274 shell: echo 'SHOW SERVER_VERSION' | psql --tuples-only --no-align --dbname postgres
275 register: postgres_version_resp
276
277 - name: Print PostgreSQL server version
278 debug:
279 msg: '{{ postgres_version_resp.stdout }}'