diff --git a/roles/matrix-client-element/tasks/main.yml b/roles/matrix-client-element/tasks/main.yml index cdc5fa97a..f020382ad 100644 --- a/roles/matrix-client-element/tasks/main.yml +++ b/roles/matrix-client-element/tasks/main.yml @@ -20,8 +20,14 @@ - setup-all - setup-client-element -- import_tasks: "{{ role_path }}/tasks/setup.yml" - when: run_setup|bool +- import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup|bool and matrix_client_element_enabled|bool" + tags: + - setup-all + - setup-client-element + +- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup|bool and not matrix_client_element_enabled|bool" tags: - setup-all - setup-client-element diff --git a/roles/matrix-client-element/tasks/setup.yml b/roles/matrix-client-element/tasks/setup_install.yml similarity index 73% rename from roles/matrix-client-element/tasks/setup.yml rename to roles/matrix-client-element/tasks/setup_install.yml index 117a09f48..908dfa00d 100644 --- a/roles/matrix-client-element/tasks/setup.yml +++ b/roles/matrix-client-element/tasks/setup_install.yml @@ -1,9 +1,5 @@ --- -# -# Tasks related to setting up Element -# - - name: Ensure Element paths exists file: path: "{{ item.path }}" @@ -87,44 +83,3 @@ service: daemon_reload: yes when: "matrix_client_element_enabled and matrix_client_element_systemd_service_result.changed" - -# -# Tasks related to getting rid of Element (if it was previously enabled) -# - -- name: Check existence of matrix-client-element.service - stat: - path: "{{ matrix_systemd_path }}/matrix-client-element.service" - register: matrix_client_element_service_stat - when: "not matrix_client_element_enabled|bool" - -- name: Ensure matrix-client-element is stopped - service: - name: matrix-client-element - state: stopped - daemon_reload: yes - register: stopping_result - when: "not matrix_client_element_enabled|bool and matrix_client_element_service_stat.stat.exists" - -- name: Ensure matrix-client-element.service doesn't exist - file: - path: "{{ matrix_systemd_path }}/matrix-client-element.service" - state: absent - when: "not matrix_client_element_enabled|bool and matrix_client_element_service_stat.stat.exists" - -- name: Ensure systemd reloaded after matrix-client-element.service removal - service: - daemon_reload: yes - when: "not matrix_client_element_enabled|bool and matrix_client_element_service_stat.stat.exists" - -- name: Ensure Element paths doesn't exist - file: - path: "{{ matrix_client_element_data_path }}" - state: absent - when: "not matrix_client_element_enabled|bool" - -- name: Ensure Element Docker image doesn't exist - docker_image: - name: "{{ matrix_client_element_docker_image }}" - state: absent - when: "not matrix_client_element_enabled|bool" diff --git a/roles/matrix-client-element/tasks/setup_uninstall.yml b/roles/matrix-client-element/tasks/setup_uninstall.yml new file mode 100644 index 000000000..398a17e29 --- /dev/null +++ b/roles/matrix-client-element/tasks/setup_uninstall.yml @@ -0,0 +1,38 @@ +--- + +- name: Check existence of matrix-client-element.service + stat: + path: "{{ matrix_systemd_path }}/matrix-client-element.service" + register: matrix_client_element_service_stat + when: "not matrix_client_element_enabled|bool" + +- name: Ensure matrix-client-element is stopped + service: + name: matrix-client-element + state: stopped + daemon_reload: yes + register: stopping_result + when: "not matrix_client_element_enabled|bool and matrix_client_element_service_stat.stat.exists" + +- name: Ensure matrix-client-element.service doesn't exist + file: + path: "{{ matrix_systemd_path }}/matrix-client-element.service" + state: absent + when: "not matrix_client_element_enabled|bool and matrix_client_element_service_stat.stat.exists" + +- name: Ensure systemd reloaded after matrix-client-element.service removal + service: + daemon_reload: yes + when: "not matrix_client_element_enabled|bool and matrix_client_element_service_stat.stat.exists" + +- name: Ensure Element paths doesn't exist + file: + path: "{{ matrix_client_element_data_path }}" + state: absent + when: "not matrix_client_element_enabled|bool" + +- name: Ensure Element Docker image doesn't exist + docker_image: + name: "{{ matrix_client_element_docker_image }}" + state: absent + when: "not matrix_client_element_enabled|bool" diff --git a/roles/matrix-client-hydrogen/tasks/main.yml b/roles/matrix-client-hydrogen/tasks/main.yml index 6534db05d..8d5c493f5 100644 --- a/roles/matrix-client-hydrogen/tasks/main.yml +++ b/roles/matrix-client-hydrogen/tasks/main.yml @@ -8,8 +8,14 @@ - setup-all - setup-client-hydrogen -- import_tasks: "{{ role_path }}/tasks/setup.yml" - when: run_setup|bool +- import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup|bool and matrix_client_hydrogen_enabled|bool" + tags: + - setup-all + - setup-client-hydrogen + +- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup|bool and not matrix_client_hydrogen_enabled|bool" tags: - setup-all - setup-client-hydrogen diff --git a/roles/matrix-client-hydrogen/tasks/setup.yml b/roles/matrix-client-hydrogen/tasks/setup_install.yml similarity index 70% rename from roles/matrix-client-hydrogen/tasks/setup.yml rename to roles/matrix-client-hydrogen/tasks/setup_install.yml index a4ff7c3cc..0c0dcf3b5 100644 --- a/roles/matrix-client-hydrogen/tasks/setup.yml +++ b/roles/matrix-client-hydrogen/tasks/setup_install.yml @@ -1,9 +1,5 @@ --- -# -# Tasks related to setting up Hydrogen -# - - name: Ensure Hydrogen paths exists file: path: "{{ item.path }}" @@ -78,44 +74,3 @@ service: daemon_reload: yes when: "matrix_client_hydrogen_enabled and matrix_client_hydrogen_systemd_service_result.changed" - -# -# Tasks related to getting rid of Hydrogen (if it was previously enabled) -# - -- name: Check existence of matrix-client-hydrogen.service - stat: - path: "{{ matrix_systemd_path }}/matrix-client-hydrogen.service" - register: matrix_client_hydrogen_service_stat - when: "not matrix_client_hydrogen_enabled|bool" - -- name: Ensure matrix-client-hydrogen is stopped - service: - name: matrix-client-hydrogen - state: stopped - daemon_reload: yes - register: stopping_result - when: "not matrix_client_hydrogen_enabled|bool and matrix_client_hydrogen_service_stat.stat.exists" - -- name: Ensure matrix-client-hydrogen.service doesn't exist - file: - path: "{{ matrix_systemd_path }}/matrix-client-hydrogen.service" - state: absent - when: "not matrix_client_hydrogen_enabled|bool and matrix_client_hydrogen_service_stat.stat.exists" - -- name: Ensure systemd reloaded after matrix-client-hydrogen.service removal - service: - daemon_reload: yes - when: "not matrix_client_hydrogen_enabled|bool and matrix_client_hydrogen_service_stat.stat.exists" - -- name: Ensure Hydrogen paths doesn't exist - file: - path: "{{ matrix_client_hydrogen_data_path }}" - state: absent - when: "not matrix_client_hydrogen_enabled|bool" - -- name: Ensure Hydrogen Docker image doesn't exist - docker_image: - name: "{{ matrix_client_hydrogen_docker_image }}" - state: absent - when: "not matrix_client_hydrogen_enabled|bool" diff --git a/roles/matrix-client-hydrogen/tasks/setup_uninstall.yml b/roles/matrix-client-hydrogen/tasks/setup_uninstall.yml new file mode 100644 index 000000000..455b5a8d9 --- /dev/null +++ b/roles/matrix-client-hydrogen/tasks/setup_uninstall.yml @@ -0,0 +1,38 @@ +--- + +- name: Check existence of matrix-client-hydrogen.service + stat: + path: "{{ matrix_systemd_path }}/matrix-client-hydrogen.service" + register: matrix_client_hydrogen_service_stat + when: "not matrix_client_hydrogen_enabled|bool" + +- name: Ensure matrix-client-hydrogen is stopped + service: + name: matrix-client-hydrogen + state: stopped + daemon_reload: yes + register: stopping_result + when: "not matrix_client_hydrogen_enabled|bool and matrix_client_hydrogen_service_stat.stat.exists" + +- name: Ensure matrix-client-hydrogen.service doesn't exist + file: + path: "{{ matrix_systemd_path }}/matrix-client-hydrogen.service" + state: absent + when: "not matrix_client_hydrogen_enabled|bool and matrix_client_hydrogen_service_stat.stat.exists" + +- name: Ensure systemd reloaded after matrix-client-hydrogen.service removal + service: + daemon_reload: yes + when: "not matrix_client_hydrogen_enabled|bool and matrix_client_hydrogen_service_stat.stat.exists" + +- name: Ensure Hydrogen paths doesn't exist + file: + path: "{{ matrix_client_hydrogen_data_path }}" + state: absent + when: "not matrix_client_hydrogen_enabled|bool" + +- name: Ensure Hydrogen Docker image doesn't exist + docker_image: + name: "{{ matrix_client_hydrogen_docker_image }}" + state: absent + when: "not matrix_client_hydrogen_enabled|bool"