diff --git a/.idea/misc.xml b/.idea/misc.xml index 639900d..6e86672 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/tasks/main.yml b/tasks/main.yml index 503b97b..7108640 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,40 +1,11 @@ --- -- name: "Run Update-Check" - become: true - become_user: "{{ nextcloud_user }}" - shell: - cmd: "{{ php_binary }} {{ php_arguments }} {{ nextcloud_path }}/occ update:check --no-interaction --no-warnings" - register: nextcloud_update_check_output - -- name: "Parse Update-Check Output" - ansible.builtin.set_fact: - nextcloud_update_needed: "{{ nextcloud_update_check_output.stdout | regex_search('Nextcloud\\s[^\\n]*\\sis\\savailable') | bool }}" - -- name: "Enable Maintenance-Mode" - include_tasks: "occ_command.yml" +- name: "Run main loop" + include_tasks: "main_loop.yml" vars: - occ_command: "maintenance:mode --on" - -- name: "Run Update" - include_tasks: "update.yml" - when: nextcloud_update_needed - -- name: "Run Maintenance tasks" - include_tasks: "occ_command.yml" - vars: - occ_command: "{{ item }}" - loop: - - "maintenance:repair --no-interaction" - - "app:update --all --no-interaction" - - "maintenance:update:htaccess --no-interaction" - - "db:add-missing-columns --no-interaction" - - "db:add-missing-indices --no-interaction" - - "db:add-missing-primary-keys --no-interaction" - - "db:convert-filecache-bigint --no-interaction" - - "db:convert-mysql-charset --no-interaction" - -- name: "Disable Maintenance-Mode" - include_tasks: "occ_command.yml" - vars: - occ_command: "maintenance:mode --off" - + nextcloud_user: "{{ nc_instance.nextcloud_user }}" + nextcloud_path: "{{ nc_instance.nextcloud_path }}" + php_binary: "{{ nc_instance.php_binary }}" + php_arguments: "{{ nc_instance.php_arguments }}" + loop_control: + loop_var: "nc_instance" + loop: "{{ nextcloud_instances }}" \ No newline at end of file diff --git a/tasks/main_loop.yml b/tasks/main_loop.yml new file mode 100644 index 0000000..98767ae --- /dev/null +++ b/tasks/main_loop.yml @@ -0,0 +1,42 @@ +--- +- name: "Run Update-Check" + become: true + become_user: "{{ nextcloud_user }}" + shell: + cmd: "{{ php_binary }} {{ php_arguments }} {{ nextcloud_path }}/occ update:check --no-interaction --no-warnings" + register: nextcloud_update_check_output + +- name: "Parse Update-Check Output" + ansible.builtin.set_fact: + nextcloud_update_needed: "{{ nextcloud_update_check_output.stdout | regex_search(update_regex) }}" + vars: + update_regex: 'Nextcloud [\d\.]+ is available' + +- name: "Main Update block" + when: "nextcloud_update_needed" + block: + - name: "Run Update" + include_tasks: "update.yml" + when: nextcloud_update_needed + + +- name: "Run Maintenance tasks (after update)" + include_tasks: "occ_command.yml" + vars: + occ_command: "{{ item }}" + loop: + - "maintenance:repair --no-interaction" + when: "nextcloud_update_needed" + +- name: "Run Maintenance tasks" + include_tasks: "occ_command.yml" + vars: + occ_command: "{{ item }}" + loop: + - "app:update --all --no-interaction" + - "maintenance:update:htaccess --no-interaction" + - "db:add-missing-columns --no-interaction" + - "db:add-missing-indices --no-interaction" + - "db:add-missing-primary-keys --no-interaction" + - "db:convert-filecache-bigint --no-interaction" + - "db:convert-mysql-charset --no-interaction" diff --git a/tasks/occ_command.yml b/tasks/occ_command.yml index 36df4c8..131c173 100644 --- a/tasks/occ_command.yml +++ b/tasks/occ_command.yml @@ -4,3 +4,4 @@ become_user: "{{ nextcloud_user }}" shell: cmd: "{{ php_binary }} {{ php_arguments }} {{ nextcloud_path }}/occ {{ occ_command }}" + register: nc_occ_output \ No newline at end of file diff --git a/tasks/update.yml b/tasks/update.yml index 80c5583..3d0f721 100644 --- a/tasks/update.yml +++ b/tasks/update.yml @@ -3,7 +3,7 @@ become: true become_user: "{{ nextcloud_user }}" shell: - cmd: "{{ php_binary }} {{ php_arguments }} {{ nextcloud_path }}/updater/updater.phar --no-interaction" + cmd: "alias \"php={{ php_binary }} {{ php_arguments }}\"; php {{ nextcloud_path }}/updater/updater.phar --no-interaction" - name: "Disable Maintenance-Mode" include_tasks: "occ_command.yml" @@ -18,4 +18,4 @@ - name: "Disable Maintenance-Mode" include_tasks: "occ_command.yml" vars: - occ_command: "maintenance:mode --on" \ No newline at end of file + occ_command: "maintenance:mode --off" \ No newline at end of file