ansible/roles/nextcloud/tasks/core/integrity.yml
Salt 11d0cad9fb Add Nextcloud
AND BOY DOES IT SMELL
2020-11-01 04:55:05 -06:00

98 lines
3.0 KiB
YAML

---
- name: Read extra files
block:
- name: Run integrity check for core
command: "php occ integrity:check-core --output=json"
args:
chdir: "{{ nextcloud_installation_dir }}"
register: nextcloud_integrity_core
become: true
become_user: "{{ nextcloud_file_owner }}"
failed_when: false
changed_when: false
- name: Run integrity check for apps
command: "php occ integrity:check-app {{ item }} --output=json"
args:
chdir: "{{ nextcloud_installation_dir }}"
register: nextcloud_integrity_apps
loop: >-
{{
(
nextcloud_installed_apps.enabled
| combine(nextcloud_installed_apps.disabled)
).keys()
| list
}}
changed_when: false
failed_when: false
become: true
become_user: "{{ nextcloud_file_owner }}"
- name: Extract extra files that need deletion
set_fact:
nextcloud_extra_files: >-
[
{%- for result in nextcloud_integrity_apps.results -%}
{%- set appname=result.item -%}
{%- set files=(result.stdout_lines[-1] | from_json) -%}
{%- if files is mapping and 'EXTRA_FILE' in files -%}
"{{ []
| zip_longest(
files['EXTRA_FILE'].keys(),
fillvalue=("apps/" ~ appname)
)
| map('join', '/')
| list
| join('","') }}"
,
{%- endif -%}
{%- endfor -%}
{%- set files=(
nextcloud_integrity_core.stdout_lines[-1]
| from_json
)
-%}
{%- if files is mapping and 'EXTRA_FILE' in files -%}
'{{ files["EXTRA_FILE"].keys() | join("','") }}'
{%- endif -%}
]
- name: Delete extra files
block:
# Using `command` instead of `file` with a loop to make it (much) faster.
- name: Delete files found by integrity check
command: >-
rm -f '{{ nextcloud_extra_files | join("' '") }}'
args:
chdir: "{{ nextcloud_installation_dir }}"
warn: false
- name: Re-run integrity check for core to update integrity results
command: "php occ integrity:check-core --output=json"
args:
chdir: "{{ nextcloud_installation_dir }}"
become: true
become_user: "{{ nextcloud_file_owner }}"
failed_when: false
changed_when: false
- name: Re-run integrity check for apps to update integrity results
command: "php occ integrity:check-app {{ item }} --output=json"
args:
chdir: "{{ nextcloud_installation_dir }}"
loop: >-
{{
(
nextcloud_installed_apps.enabled
| combine(nextcloud_installed_apps.disabled)
).keys()
| list
}}
changed_when: false
failed_when: false
become: true
become_user: "{{ nextcloud_file_owner }}"
when: nextcloud_extra_files | length > 0