diff --git a/defaults/main.yaml b/defaults/main.yaml index 2183125..c1dc0ea 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -1,4 +1,6 @@ --- +borgmatic_enabled: true + borgmatic_ssh_keys: [] borgmatic_config: diff --git a/tasks/init.yaml b/tasks/init.yaml index a0401dc..d7977a3 100644 --- a/tasks/init.yaml +++ b/tasks/init.yaml @@ -20,8 +20,8 @@ - name: Initialize borg check_repositories ansible.builtin.shell: "borgmatic init --encryption repokey" - environment: - PATH: "{{ ansible_env.PATH}}:/usr/local/bin" + environment: + PATH: "{{ ansible_env.PATH}}:/usr/local/bin" - name: Enable borgmatic.timer ansible.builtin.systemd: diff --git a/tasks/main.yaml b/tasks/main.yaml index 5688812..126ccce 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -4,6 +4,15 @@ with_first_found: - "os/{{ ansible_os_family }}/{{ ansible_distribution_major_version }}.yaml" - "os/{{ ansible_os_family }}.yaml" -- include_tasks: install.yaml -- include_tasks: config.yaml -- include_tasks: init.yaml + +- name: Borgmatic - Install and configure + when: borgmatic_enabled | default(true) + block: + - include_tasks: install.yaml + - include_tasks: config.yaml + - include_tasks: init.yaml + +- name: Borgmatic - Uninstall and clean up + when: not borgmatic_enabled | default(true) + block: + - include_tasks: uninstall.yaml diff --git a/tasks/uninstall.yaml b/tasks/uninstall.yaml new file mode 100644 index 0000000..80e9bbb --- /dev/null +++ b/tasks/uninstall.yaml @@ -0,0 +1,33 @@ +--- +- name: Disable borgmatic.timer if installed + ansible.builtin.systemd: + name: borgmatic.timer + enabled: false + masked: true + state: stopped + +- name: Remove borgmatic systemd units + ansible.builtin.file: + path: "/etc/systemd/system/{{ item }}" + state: absent + loop: + - borgmatic.service + - borgmatic.timer + when: + - borgmatic_install_from_pip | default(false) + notify: reload systemd + +- name: Uninstall borgmatic package + ansible.builtin.package: + name: borgmatic + state: absent + +- name: Remove borgmatic configuration directory + ansible.builtin.file: + path: "/etc/borgmatic" + state: absent + +- name: Remove borgmatic files in the root user home + ansible.builtin.file: + path: "/root/.borgmatic" + state: absent