From c37cf424277f31dba3e01907f9f3fb68f8ee0fe1 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Thu, 24 Nov 2022 17:06:31 +0200 Subject: [PATCH] Do not delete and re-create Synapse worker configs needlessly We had checks to avoid stopping/deleting systemd services for workers that used to exist and will continue to exist, but we were deleting config files for workers each time.. Only to recreate them again later. This lead to: - too many misleading "changed" tasks - too much unnecessary work - potential failures during playbook execution possibly leaving the system in a bad state (no worker config files) --- .../tasks/synapse/workers/setup_install.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/roles/custom/matrix-synapse/tasks/synapse/workers/setup_install.yml b/roles/custom/matrix-synapse/tasks/synapse/workers/setup_install.yml index 0f2105ed..d6c50397 100644 --- a/roles/custom/matrix-synapse/tasks/synapse/workers/setup_install.yml +++ b/roles/custom/matrix-synapse/tasks/synapse/workers/setup_install.yml @@ -7,12 +7,16 @@ use_regex: true register: matrix_synapse_workers_current_config_files +- set_fact: + matrix_synapse_enabled_worker_names: "{{ matrix_synapse_workers_enabled_list | map(attribute='name') }}" + # This also deletes some things which we need. They will be recreated below. -- name: Ensure previous worker configs are cleaned +- name: Ensure unnecessary worker configs are cleaned ansible.builtin.file: path: "{{ item.path }}" state: absent with_items: "{{ matrix_synapse_workers_current_config_files.files }}" + when: "not ansible_check_mode and (item.path | basename | replace ('worker.', '') | replace('.yaml', '')) not in matrix_synapse_enabled_worker_names" - name: Determine current worker systemd services ansible.builtin.find: @@ -27,13 +31,14 @@ state: stopped enabled: false with_items: "{{ matrix_synapse_workers_current_systemd_services.files }}" - when: "not ansible_check_mode and item.path | basename not in devture_systemd_service_manager_services_list | map(attribute='name')" + when: "not ansible_check_mode and (item.path | basename | replace('.service', '')) not in matrix_synapse_enabled_worker_names" - name: Ensure unnecessary worker systemd services are cleaned ansible.builtin.file: path: "{{ item.path }}" state: absent with_items: "{{ matrix_synapse_workers_current_systemd_services.files }}" + when: "not ansible_check_mode and (item.path | basename | replace('.service', '')) not in matrix_synapse_enabled_worker_names" - name: Ensure creation of worker systemd service files and configuration files ansible.builtin.include_tasks: "{{ role_path }}/tasks/synapse/workers/util/setup_files_for_worker.yml"