1 #####################################
2 ### someone"s ansible provisioner ###
3 #####################################
4 # Part of: https://git.somenet.org/root/pub/somesible.git
5 # 2017-2025 by someone <someone@somenet.org>
8 #- name: create postgres-db and user
10 # name: util/postgres-db-usr
13 # db_server_delegate: "{{nextcloud_db_server_delegate}}"
14 # dbname: "{{nextcloud_db_name}}"
15 # pw: "{{nextcloud_db_pw}}"
16 # when: nextcloud_db_create | default('True')
19 - name: include vars_nginx_vhost_custom
22 name: vars_nginx_vhost_custom
24 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/{{nextcloud_domain}}-vars_nginx_vhost_custom.yml"
25 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/{{nextcloud_domain}}-vars_nginx_vhost_custom.yml"
26 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/{{nextcloud_domain}}-vars_nginx_vhost_custom.yml"
27 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/vars_nginx_vhost_custom.yml"
28 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/vars_nginx_vhost_custom.yml"
29 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/vars_nginx_vhost_custom.yml"
30 - "default/vars_nginx_vhost_custom.yml"
33 - name: configure vhost
35 name: server/nginx/vhost-unified
37 vhost_type: "custom+php"
38 vhost_name: "{{nextcloud_domain}}"
39 vhost_php_custom: ["bzip2", "php8.2-apcu", "php8.2-bcmath", "php8.2-pgsql", "php8.2-curl", "php8.2-gd", "php8.2-gmp", "php8.2-intl", "php-imagick", "php8.2-mbstring", "php8.2-xml", "php8.2-zip"]
40 vhost_dotfile_protection: False
42 vhost_custom_pre_server: "{{vars_nginx_vhost_custom.vhost_custom_pre_server}}"
43 vhost_custom: "{{vars_nginx_vhost_custom.vhost_custom}}"
46 - name: set up data-dir
48 path: "{{nextcloud_data_dir_path}}"
55 - name: set up log-dir
57 path: "/var/log/nextcloud/"
64 - name: nextcloud logrotate config
67 dest: "/etc/logrotate.d/nextcloud"
72 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/nextcloud.logrotate"
73 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/nextcloud.logrotate"
74 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/nextcloud.logrotate"
75 - "default/nextcloud.logrotate"
78 - name: download nextcloud release and check checksums
80 url: "{{nextcloud_download_url}}"
81 dest: "/var/www/{{nextcloud_domain}}-nextcloud.tar.bz2"
85 checksum: "{{nextcloud_download_checksum}}"
91 - name: set up new webroot-dir
93 path: "/var/www/{{nextcloud_domain}}.tmp"
98 when: download.changed
101 - name: download and extract nextcloud files
103 src: "/var/www/{{nextcloud_domain}}-nextcloud.tar.bz2"
104 dest: "/var/www/{{nextcloud_domain}}.tmp"
106 mode: "u=rwX,g=rX,o-rwx"
110 - '--strip-components=1'
111 - '--show-stored-names'
112 when: download.changed
115 - name: use existing config file
116 command: "mv /var/www/{{nextcloud_domain}}/config/config.php /var/www/{{nextcloud_domain}}.tmp/config/"
118 removes: "/var/www/{{nextcloud_domain}}/config/config.php"
119 when: download.changed
122 - name: remove old files
124 path: "/var/www/{{nextcloud_domain}}"
126 when: download.changed
129 - name: move newly extracted files to destination
130 command: "mv /var/www/{{nextcloud_domain}}.tmp /var/www/{{nextcloud_domain}}"
132 creates: "/var/www/{{nextcloud_domain}}"
133 when: download.changed
136 - name: remove possibly left over files
138 path: "/var/www/{{nextcloud_domain}}.tmp"
140 when: download.changed
143 - name: install nextcloud
145 become_user: "www-data"
147 php occ maintenance:install
149 --database-host="{{nextcloud_db_host}}"
150 --database-name="{{nextcloud_db_name}}"
151 --database-user="{{nextcloud_db_name}}"
152 --database-pass="{{nextcloud_db_pw}}"
153 --admin-user="{{nextcloud_admin_user}}"
154 --admin-pass="{{nextcloud_admin_pw}}"
155 --data-dir="{{nextcloud_data_dir_path}}/data"
157 chdir: "/var/www/{{nextcloud_domain}}"
158 creates: "/var/www/{{nextcloud_domain}}/config/config.php"
159 when: download.changed
162 - name: write-unlock config
164 become_user: "www-data"
166 path: "/var/www/{{nextcloud_domain}}/config/config.php"
168 regexp: 'config_is_read_only'
172 - name: finish nextcloud upgrade by running occ upgrade
174 become_user: "www-data"
175 shell: 'php --define apc.enable_cli=1 occ upgrade'
177 chdir: "/var/www/{{nextcloud_domain}}"
179 changed_when: "'Nextcloud is already latest version' not in script_res.stdout"
182 - name: ensure trusted domains are set
184 become_user: "www-data"
185 shell: 'echo "prev-$(php --define apc.enable_cli=1 occ config:system:get trusted_domains {{ item.0 }})-"; php --define apc.enable_cli=1 occ config:system:set trusted_domains {{ item.0 }} --value "{{ item.1 }}"'
187 chdir: "/var/www/{{nextcloud_domain}}"
189 # changed_when: "'prev-{{item.1}}-' not in script_res.stdout"
193 - "{{nextcloud_domain}}"
198 become_user: "www-data"
199 shell: 'php --define apc.enable_cli=1 occ app:disable -- "{{ item }}"; php --define apc.enable_cli=1 occ app:install -- "{{ item }}"; true'
201 chdir: "/var/www/{{nextcloud_domain}}"
203 # changed_when: "'{{item}} already installed' not in script_res.stdout"
206 - "{{nextcloud_installed_apps[nextcloud_domain] | default(nextcloud_default_installed_apps)}}"
210 - name: finish nextcloud upgrade by running occ db:add-missing-columns
212 become_user: "www-data"
213 shell: 'php --define apc.enable_cli=1 occ db:add-missing-columns'
215 chdir: "/var/www/{{nextcloud_domain}}"
217 changed_when: "'Adding' in script_res.stdout"
220 - name: finish nextcloud upgrade by running occ db:add-missing-indices
222 become_user: "www-data"
223 shell: 'php --define apc.enable_cli=1 occ db:add-missing-indices'
225 chdir: "/var/www/{{nextcloud_domain}}"
227 changed_when: "'Adding' in script_res.stdout"
230 - name: finish nextcloud upgrade by running occ db:add-missing-primary-keys
232 become_user: "www-data"
233 shell: 'php --define apc.enable_cli=1 occ db:add-missing-primary-keys'
235 chdir: "/var/www/{{nextcloud_domain}}"
237 changed_when: "'Adding' in script_res.stdout"
240 - name: finish nextcloud upgrade by running occ maintenance:repair --include-expensive
242 become_user: "www-data"
243 shell: 'php --define apc.enable_cli=1 occ maintenance:repair --include-expensive'
245 chdir: "/var/www/{{nextcloud_domain}}"
247 changed_when: "'Adding' in script_res.stdout"
250 # Failcloud expects an unsafe config-key behavior
251 # Therefore we must use
252 # shell: 'echo "prev-$(php occ config:system:get {{ item.key }})-"; php occ config:system:set $(echo -n "{{ item.key }}" ) --value "{{ item.value }}"'
254 # shell: 'echo "prev-$(php occ config:system:get {{ item.key }})-"; php occ config:system:set "{{ item.key }}"--value "{{ item.value }}"'
255 - name: apply config options
257 become_user: "www-data"
258 shell: 'echo "prev-$(php --define apc.enable_cli=1 occ config:system:get {{ item.key }})-"; php --define apc.enable_cli=1 occ config:system:set $(echo -n "{{ item.key }}" ) --value "{{ item.value }}"'
260 chdir: "/var/www/{{nextcloud_domain}}"
262 # changed_when: "'prev-{{item.value}}-' not in script_res.stdout"
265 - "{{nextcloud_config_options[nextcloud_domain]|default(nextcloud_default_config_options)}}"
268 - name: write-lock config
270 become_user: "www-data"
271 shell: 'php --define apc.enable_cli=1 occ config:system:set config_is_read_only --value true'
273 chdir: "/var/www/{{nextcloud_domain}}"
277 - name: copy nextcloud-cron@.service to /etc/systemd/system/
280 dest: "/etc/systemd/system/nextcloud-cron@.service"
285 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/nextcloud-cron@.service"
286 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/nextcloud-cron@.service"
287 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/nextcloud-cron@.service"
288 - "default/nextcloud-cron@.service"
291 - name: copy nextcloud-cron@.timer to /etc/systemd/system/
294 dest: "/etc/systemd/system/nextcloud-cron@.timer"
299 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/nextcloud-cron@.timer"
300 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/nextcloud-cron@.timer"
301 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/nextcloud-cron@.timer"
302 - "default/nextcloud-cron@.timer"
305 - name: copy fail2ban.filter.d.nextcloud.conf to /etc/fail2ban/filter.d/
308 dest: "/etc/fail2ban/filter.d/nextcloud.conf"
313 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/fail2ban.filter.d.nextcloud.conf"
314 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/fail2ban.filter.d.nextcloud.conf"
315 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/fail2ban.filter.d.nextcloud.conf"
316 - "default/fail2ban.filter.d.nextcloud.conf"
317 notify: reload fail2ban.service
320 - name: copy fail2ban.jail.d.nextcloud.conf to /etc/fail2ban/jail.d/
323 dest: "/etc/fail2ban/jail.d/nextcloud.conf"
328 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/fail2ban.jail.d.nextcloud.conf"
329 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/fail2ban.jail.d.nextcloud.conf"
330 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/fail2ban.jail.d.nextcloud.conf"
331 - "default/fail2ban.jail.d.nextcloud.conf"
332 notify: reload fail2ban.service
335 - name: reload, enable and start nextcloud-cron@.timer.
336 include_role: name="base/systemd/enable-and-start"
338 service_name: "nextcloud-cron@{{nextcloud_domain}}.timer"