correction de config_postgres
[lhc/ansible.git] / tasks / config_nuage.yml
1 - name: Etckeeper commit if necessary
2 ansible.builtin.command: etckeeper commit "commit by ansible because installing {{ DOMAIN }}/{{ config_ss_domain }}"
3 ignore_errors: true
4
5 - name: Install required packages
6 ansible.builtin.apt:
7 name:
8 # - php-ctype
9 - php-curl
10 # - php-dom
11 # - php-fileinfo
12 - php-gd
13 - php-json
14 - "php{{ php_version }}-xml"
15 - php-mbstring
16 # - php-openssl
17 # - php-posix
18 # - php-session
19 # - php-simplexml
20 # - php-xmlreader
21 # - php-xmlwriter
22 - php-zip
23 # - php-zlib
24 # - php-pdo_pgsql
25 - "php{{ php_version }}-pgsql"
26 - php-pgsql
27 - php-intl
28 - php-bz2
29 # - php-sodium
30 - php-gmp
31 # - php-exif
32 - php-redis
33 - imagemagick
34 - php-imagick
35 - python3-psycopg2 # module ansible psql
36 state: present
37
38 - name: Boucle d'ajout du user php dans plusieurs groupe
39 ansible.builtin.user:
40 name: "php_{{ SIGLE }}_{{ config_ss_domain }}"
41 groups: "{{ item }}"
42 append: true
43 loop:
44 - nextcloud
45 - postgres-data
46 - redis
47 - "site_{{ SIGLE }}_{{ config_ss_domain }}"
48
49 - name: Bloc nouvelle version nextcloud
50 when: nouvelle_version is undefined
51 block:
52 - name: Demande la version de nextcloud à installer
53 ansible.builtin.pause:
54 prompt: "Quelle version de nextcloud doit être utilisée"
55 echo: true
56 register: nextcloud_version_prompt
57
58 - name: Definir nouvelle_version
59 ansible.builtin.set_fact:
60 nouvelle_version: "{{ nextcloud_version_prompt.user_input }}"
61
62 - name: Bloc ancienne version nextcloud
63 when: ancienne_version is undefined
64 block:
65 - name: Demande la version de nextcloud déjà installée
66 ansible.builtin.pause:
67 prompt: "Quelle version de nextcloud déjà installée"
68 echo: true
69 register: ancienne_version_prompt
70
71 - name: Definir ancienne_version
72 ansible.builtin.set_fact:
73 ancienne_version: "{{ ancienne_version_prompt.user_input }}"
74
75 - name: Inclure la verif de l'install nextcloud
76 ansible.builtin.include_tasks: tasks/verif_installation_nextcloud.yml
77
78 - name: Pour chaque base, ajouter les droits suivants à l'utilisateur php
79 become_user: postgres
80 become: true
81 community.postgresql.postgresql_privs:
82 db: "{{ item.db }}"
83 privs: "{{ item.privs }}"
84 type: "{{ item.type |default(omit) }}"
85 objs: "{{ item.objs }}"
86 role: "{{ item.role }}"
87 grant_option: "{{ item.grant_option |default(omit) }}"
88 loop_control:
89 label: "{{ item.name }}"
90 loop:
91 - db: "{{ nextcloud_db_name }}"
92 privs: "ALL"
93 type: "schema"
94 objs: "public"
95 role: "{{ nextcloud_php_user }}"
96 grant_option: true
97 name: "GRANT ALL ON SCHEMA public TO php_{{ SIGLE }}_nuage WITH GRANT OPTION;"
98
99 - name: Boucle création des répertoires app, config et data nextcloud
100 ansible.builtin.file:
101 path: "{{ item.path }}"
102 state: "{{ item.state }}"
103 owner: "{{ item.owner }}"
104 group: "{{ item.group }}"
105 mode: "{{ item.mode }}"
106 loop_control:
107 label: "{{ item.path }}"
108 loop:
109 - path: "{{ nextcloud_webroot }}/apps"
110 state: directory
111 owner: "{{ nextcloud_php_user }}"
112 group: "{{ nextcloud_websrv_user }}"
113 mode: '2750'
114 - path: "{{ nextcloud_webroot }}/config"
115 state: directory
116 owner: "{{ nextcloud_php_user }}"
117 group: "{{ nextcloud_websrv_user }}"
118 mode: '2750'
119 - path: "{{ nextcloud_webroot }}/data"
120 state: directory
121 owner: "{{ nextcloud_php_user }}"
122 group: "{{ nextcloud_websrv_user }}"
123 mode: '2750'
124
125 - name: Create nextcloud root dir symbolic link
126 ansible.builtin.file:
127 src: "{{ nextcloud_symbolic_source }}"
128 dest: "{{ nextcloud_webroot }}/nextcloud"
129 owner: nextcloud
130 group: nextcloud
131 state: link
132 follow: false
133
134 - name: Create nextcloud common app dir symbolic link
135 ansible.builtin.file:
136 src: "{{ nextcloud_common }}"
137 dest: "{{ nextcloud_webroot }}/common"
138 owner: nextcloud
139 group: nextcloud
140 state: link
141 follow: false
142
143 - name: Créer les fichiers spécifiques nextcloud
144 ansible.builtin.template:
145 src: "templates/{{ item.src }}"
146 dest: "{{ nextcloud_webroot }}/{{ item.dest }}"
147 owner: "{{ item.owner }}"
148 group: "{{ item.group }}"
149 mode: "{{ item.mode }}"
150 loop:
151 - src: "nextcloud_cron.j2"
152 dest: "cron"
153 owner: "{{ nextcloud_php_user }}"
154 group: "{{ nextcloud_websrv_user }}"
155 mode: '750'
156 - src: "nextcloud_console.j2"
157 dest: "console"
158 owner: "{{ nextcloud_websrv_user }}"
159 group: "{{ nextcloud_websrv_user }}"
160 mode: '750'
161 - src: "nextcloud_install_config.j2"
162 dest: "config/config.php"
163 owner: "{{ nextcloud_php_user }}"
164 group: "{{ nextcloud_websrv_user }}"
165 mode: '640'
166
167 - name: Recharger php
168 ansible.builtin.service:
169 name: "{{ item }}"
170 state: reloaded
171 loop:
172 - "php{{ php_version }}-fpm"
173
174 - name: Lancement du script d'installation nextcloud # noqa : command-instead-of-module
175 become_user: "{{ nextcloud_php_user }}"
176 become: true
177 ansible.builtin.command: >
178 ./console maintenance:install
179 --database='pgsql'
180 --database-name="php_{{ SIGLE }}_{{ config_ss_domain }}"
181 --database-user="php_{{ SIGLE }}_{{ config_ss_domain }}"
182 --database-host="/var/run/postgresql/"
183 --database-pass=""
184 --admin-user='admin'
185 --admin-pass='ckoideja'
186 --data-dir="/home/sites/data/{{ TLD }}/{{ DOMAIN }}/{{ config_ss_domain }}/data/"
187 args:
188 chdir: "{{ nextcloud_webroot }}"
189 register: install_result
190 ignore_errors: true
191
192 - name: Afficher les logs du script d'install
193 ansible.builtin.debug:
194 var: install_result
195 when: install_result is defined
196
197 - name: Afficher les logs du script d'install
198 ansible.builtin.fail:
199 msg: "Le script d'install a échoué: Voir les logs ci-dessus"
200 when: install_result.failed
201
202 - name: Créer les fichiers spécifiques nextcloud
203 ansible.builtin.template:
204 src: "templates/{{ item.src }}"
205 dest: "{{ nextcloud_webroot }}/{{ item.dest }}"
206 owner: "{{ item.owner }}"
207 group: "{{ item.group }}"
208 mode: "{{ item.mode }}"
209 loop:
210 - src: "nextcloud_sigle_config.j2"
211 dest: "config/{{ SIGLE }}.config.php"
212 owner: "{{ nextcloud_php_user }}"
213 group: "{{ nextcloud_websrv_user }}"
214 mode: '640'
215
216 - name: Creation d'un lien symbolique vers la configuration nextcloud common
217 ansible.builtin.file:
218 src: "../../../../nextcloud/common.config.php"
219 path: "{{ nextcloud_webroot }}/config/common.config.php"
220 owner: nextcloud
221 group: nextcloud
222 state: link
223 follow: false
224
225 - name: Pour chaque base, ajouter les droits suivants à l'utilisateur php
226 become_user: postgres
227 become: true
228 community.postgresql.postgresql_privs:
229 db: "{{ item.db }}"
230 privs: "{{ item.privs }}"
231 type: "{{ item.type | default(omit) }}"
232 objs: "{{ item.objs }}"
233 role: "{{ item.role }}"
234 grant_option: "{{ item.grant_option | default(omit) }}"
235 loop_control:
236 label: "{{ item.name }}"
237 loop:
238 - db: "{{ nextcloud_db_name }}"
239 privs: "USAGE,CREATE"
240 type: "schema"
241 objs: "public"
242 role: "{{ nextcloud_php_user }}"
243 name: "GRANT USAGE,CREATE ON SCHEMA public TO php_{{ SIGLE }}_nuage;"
244 # - db: "{{ nextcloud_db_name }}"
245 # privs: "SELECT"
246 # type: "table"
247 # objs: "pg_namespace"
248 # role: "{{ nextcloud_php_user }}"
249 # name: "GRANT SELECT ON TABLE pg_namespace TO php_{{ SIGLE }}_nuage;"
250 # - db: "{{ nextcloud_db_name }}"
251 # privs: "SELECT"
252 # type: "table"
253 # objs: "pg_collation"
254 # role: "{{ nextcloud_php_user }}"
255 # name: "GRANT SELECT ON TABLE pg_collation TO php_{{ SIGLE }}_nuage;"
256 # - db: "{{ nextcloud_db_name }}"
257 # privs: "SELECT"
258 # type: "table"
259 # objs: "pg_index"
260 # role: "{{ nextcloud_php_user }}"
261 # name: "GRANT SELECT ON TABLE pg_index TO php_{{ SIGLE }}_nuage;"
262 # - db: "{{ nextcloud_db_name }}"
263 # privs: "SELECT"
264 # type: "table"
265 # objs: "pg_attrdef"
266 # role: "{{ nextcloud_php_user }}"
267 # name: "GRANT SELECT ON TABLE pg_attrdef TO php_{{ SIGLE }}_nuage;"
268 # - db: "{{ nextcloud_db_name }}"
269 # privs: "SELECT"
270 # type: "table"
271 # objs: "pg_description"
272 # role: "{{ nextcloud_php_user }}"
273 # name: "GRANT SELECT ON TABLE pg_description TO php_{{ SIGLE }}_nuage;"
274 # - db: "{{ nextcloud_db_name }}"
275 # privs: "SELECT"
276 # type: "table"
277 # objs: "pg_settings"
278 # role: "{{ nextcloud_php_user }}"
279 # name: "GRANT SELECT ON TABLE pg_settings TO php_{{ SIGLE }}_nuage;"
280 # - db: "{{ nextcloud_db_name }}"
281 # privs: "SELECT"
282 # objs: "pg_database"
283 # role: "{{ nextcloud_php_user }}"
284 # name: "GRANT SELECT ON pg_database TO php_{{ SIGLE }}_nuage;"
285
286 - name: Creation d'un fichier cron pour /etc/cron.d
287 ansible.builtin.cron:
288 name: "nextcloud {{ SIGLE }}_{{ config_ss_domain }} taches d'arriere plan toutes les 5 mins"
289 minute: "*/5"
290 user: "php_{{ SIGLE }}_{{ config_ss_domain }}"
291 job: "{{ nextcloud_webroot }}/cron"
292
293 - name: Recharger plusieurs services
294 ansible.builtin.service:
295 name: "{{ item }}"
296 state: reloaded
297 loop:
298 - "php{{ php_version }}-fpm"
299 - "nginx"