2019-08-13 13:26:40 +02:00
|
|
|
---
|
2022-01-10 14:19:53 +01:00
|
|
|
- name: (INSTALL) install and verify restic binary
|
2021-10-13 23:35:37 +02:00
|
|
|
become: true
|
2021-08-03 23:16:34 +02:00
|
|
|
block:
|
2022-01-10 14:19:53 +01:00
|
|
|
- name: (INSTALL) Download client binary
|
2021-08-03 23:16:34 +02:00
|
|
|
ansible.builtin.get_url:
|
|
|
|
url: '{{ restic_url }}'
|
|
|
|
dest: '{{ restic_download_path }}/restic.bz2'
|
|
|
|
force: true
|
2022-04-01 11:07:12 +02:00
|
|
|
mode: 0644
|
2021-08-03 23:16:34 +02:00
|
|
|
register: get_url_restic
|
2019-08-13 13:26:40 +02:00
|
|
|
|
2021-08-03 23:16:34 +02:00
|
|
|
# TODO: This needs to become independent of the shell module to actually work
|
2022-01-10 14:19:53 +01:00
|
|
|
- name: (INSTALL) Decompress the binary
|
2021-08-03 23:16:34 +02:00
|
|
|
ansible.builtin.shell: "bzip2 -dc {{ get_url_restic.dest }} > {{ restic_bin_bath }}"
|
|
|
|
args:
|
|
|
|
creates: '{{ restic_download_path }}/bin/restic-{{ restic_version }}'
|
2019-08-13 13:26:40 +02:00
|
|
|
|
2022-01-10 14:19:53 +01:00
|
|
|
- name: (INSTALL) Ensure permissions are correct
|
2021-08-03 23:16:34 +02:00
|
|
|
ansible.builtin.file:
|
|
|
|
path: '{{ restic_download_path }}/bin/restic-{{ restic_version }}'
|
|
|
|
mode: '0755'
|
|
|
|
owner: '{{ restic_dir_owner }}'
|
|
|
|
group: '{{ restic_dir_group }}'
|
2019-08-13 13:26:40 +02:00
|
|
|
|
2022-01-10 14:19:53 +01:00
|
|
|
- name: (INSTALL) Test the binary
|
2021-08-03 23:16:34 +02:00
|
|
|
ansible.builtin.command: "{{ restic_bin_bath }} version"
|
|
|
|
ignore_errors: true
|
|
|
|
register: restic_test_result
|
2022-04-01 11:07:12 +02:00
|
|
|
changed_when: false
|
2020-08-30 22:04:11 +02:00
|
|
|
|
2022-01-10 14:19:53 +01:00
|
|
|
- name: (INSTALL) Remove faulty binary
|
2021-08-03 23:16:34 +02:00
|
|
|
ansible.builtin.file:
|
|
|
|
path: '{{ restic_bin_bath }}'
|
|
|
|
state: absent
|
|
|
|
when: "'FAILED' in restic_test_result.stderr"
|
2020-08-30 22:04:11 +02:00
|
|
|
|
2022-01-10 14:19:53 +01:00
|
|
|
- name: (INSTALL) Fail if restic could not be installed
|
2021-08-03 23:16:34 +02:00
|
|
|
ansible.builtin.fail:
|
|
|
|
msg: >-
|
|
|
|
Restic binary has been faulty and has been removed.
|
|
|
|
Try to re-run the role and make sure you have bzip2 installed!
|
|
|
|
when: "'FAILED' in restic_test_result.stderr"
|
2020-08-30 22:04:11 +02:00
|
|
|
|
2022-01-10 14:19:53 +01:00
|
|
|
- name: (INSTALL) Create symbolic link to the correct version
|
2021-08-03 23:16:34 +02:00
|
|
|
ansible.builtin.file:
|
|
|
|
src: '{{ restic_download_path }}/bin/restic-{{ restic_version }}'
|
|
|
|
path: '{{ restic_install_path }}/restic'
|
|
|
|
state: link
|
|
|
|
force: true
|
|
|
|
rescue:
|
2022-01-10 14:19:53 +01:00
|
|
|
- name: (INSTALL) try restic self-update
|
2021-08-03 23:16:34 +02:00
|
|
|
become: true
|
|
|
|
ansible.builtin.command: "{{ restic_install_path }}/restic self-update"
|
2022-04-01 11:07:12 +02:00
|
|
|
changed_when: true
|