1 #####################################
2 ### someone"s ansible provisioner ###
3 #####################################
4 # Part of: https://git.somenet.org/root/pub/somesible.git
5 # 2017-2024 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 gitweb 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: download nextcloud release and check checksums
57 url: "{{nextcloud_download_url}}"
58 dest: "/var/www/{{nextcloud_domain}}-nextcloud.tar.bz2"
62 checksum: "{{nextcloud_download_checksum}}"
68 - name: set up new webroot-dir
70 path: "/var/www/{{nextcloud_domain}}.tmp"
75 when: download.changed
78 - name: download and extract nextcloud files
80 src: "/var/www/{{nextcloud_domain}}-nextcloud.tar.bz2"
81 dest: "/var/www/{{nextcloud_domain}}.tmp"
83 mode: "u=rwX,g=rX,o-rwx"
87 - '--strip-components=1'
88 - '--show-stored-names'
89 when: download.changed
92 - name: use existing config file
93 command: "mv /var/www/{{nextcloud_domain}}/config/config.php /var/www/{{nextcloud_domain}}.tmp/config/"
95 removes: "/var/www/{{nextcloud_domain}}/config/config.php"
96 when: download.changed
99 - name: remove old files
101 path: "/var/www/{{nextcloud_domain}}"
103 when: download.changed
106 - name: move newly extracted files to destination
107 command: "mv /var/www/{{nextcloud_domain}}.tmp /var/www/{{nextcloud_domain}}"
109 creates: "/var/www/{{nextcloud_domain}}"
110 when: download.changed
113 - name: remove possibly left over files
115 path: "/var/www/{{nextcloud_domain}}.tmp"
117 when: download.changed
120 - name: install nextcloud
122 become_user: "www-data"
124 php occ maintenance:install
126 --database-host="{{nextcloud_db_host}}"
127 --database-name="{{nextcloud_db_name}}"
128 --database-user="{{nextcloud_db_name}}"
129 --database-pass="{{nextcloud_db_pw}}"
130 --admin-user="{{nextcloud_admin_user}}"
131 --admin-pass="{{nextcloud_admin_pw}}"
132 --data-dir="{{nextcloud_data_dir_path}}/data"
134 chdir: "/var/www/{{nextcloud_domain}}"
135 creates: "/var/www/{{nextcloud_domain}}/config/config.php"
136 when: download.changed
139 - name: write-unlock config
141 become_user: "www-data"
143 path: "/var/www/{{nextcloud_domain}}/config/config.php"
145 regexp: 'config_is_read_only'
149 - name: finish nextcloud upgrade by running occ upgrade
151 become_user: "www-data"
152 shell: 'php --define apc.enable_cli=1 occ upgrade'
154 chdir: "/var/www/{{nextcloud_domain}}"
156 changed_when: "'Nextcloud is already latest version' not in script_res.stdout"
159 - name: ensure trusted domains are set
161 become_user: "www-data"
162 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 }}"'
164 chdir: "/var/www/{{nextcloud_domain}}"
166 # changed_when: "'prev-{{item.1}}-' not in script_res.stdout"
170 - "{{nextcloud_domain}}"
175 become_user: "www-data"
176 shell: 'php --define apc.enable_cli=1 occ app:install -- "{{ item }}" || true'
178 chdir: "/var/www/{{nextcloud_domain}}"
180 # changed_when: "'{{item}} already installed' not in script_res.stdout"
183 - "{{nextcloud_installed_apps}}"
187 - name: finish nextcloud upgrade by running occ db:add-missing-columns
189 become_user: "www-data"
190 shell: 'php --define apc.enable_cli=1 occ db:add-missing-columns'
192 chdir: "/var/www/{{nextcloud_domain}}"
194 changed_when: "'Adding' in script_res.stdout"
197 - name: finish nextcloud upgrade by running occ db:add-missing-indices
199 become_user: "www-data"
200 shell: 'php --define apc.enable_cli=1 occ db:add-missing-indices'
202 chdir: "/var/www/{{nextcloud_domain}}"
204 changed_when: "'Adding' in script_res.stdout"
207 - name: finish nextcloud upgrade by running occ db:add-missing-primary-keys
209 become_user: "www-data"
210 shell: 'php --define apc.enable_cli=1 occ db:add-missing-primary-keys'
212 chdir: "/var/www/{{nextcloud_domain}}"
214 changed_when: "'Adding' in script_res.stdout"
217 - name: finish nextcloud upgrade by running occ maintenance:repair --include-expensive
219 become_user: "www-data"
220 shell: 'php --define apc.enable_cli=1 occ maintenance:repair --include-expensive'
222 chdir: "/var/www/{{nextcloud_domain}}"
224 changed_when: "'Adding' in script_res.stdout"
227 # Failcloud expects an unsafe config-key behavior
228 # Therefore we must use
229 # shell: 'echo "prev-$(php occ config:system:get {{ item.key }})-"; php occ config:system:set $(echo -n "{{ item.key }}" ) --value "{{ item.value }}"'
231 # shell: 'echo "prev-$(php occ config:system:get {{ item.key }})-"; php occ config:system:set "{{ item.key }}"--value "{{ item.value }}"'
232 - name: apply config options
234 become_user: "www-data"
235 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 }}"'
237 chdir: "/var/www/{{nextcloud_domain}}"
239 # changed_when: "'prev-{{item.value}}-' not in script_res.stdout"
242 - "{{nextcloud_config_options[nextcloud_domain]}}"
245 - name: write-lock config
247 become_user: "www-data"
248 shell: 'php --define apc.enable_cli=1 occ config:system:set config_is_read_only --value true'
250 chdir: "/var/www/{{nextcloud_domain}}"
254 - name: copy nextcloud-cron@.service to /etc/systemd/system/
257 dest: "/etc/systemd/system/nextcloud-cron@.service"
262 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/nextcloud-cron@.service"
263 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/nextcloud-cron@.service"
264 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/nextcloud-cron@.service"
265 - "default/nextcloud-cron@.service"
268 - name: copy nextcloud-cron@.timer to /etc/systemd/system/
271 dest: "/etc/systemd/system/nextcloud-cron@.timer"
276 - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/nextcloud-cron@.timer"
277 - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/nextcloud-cron@.timer"
278 - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/nextcloud-cron@.timer"
279 - "default/nextcloud-cron@.timer"
282 - name: reload, enable and start nextcloud-cron@.timer.
283 include_role: name="base/systemd/enable-and-start"
285 service_name: "nextcloud-cron@{{nextcloud_domain}}.timer"