mirror of
https://github.com/roles-ansible/ansible_role_restic/
synced 2024-11-14 15:40:18 +01:00
55 lines
1.9 KiB
YAML
55 lines
1.9 KiB
YAML
---
|
|
- name: (INSTALL) install and verify restic binary
|
|
become: true
|
|
block:
|
|
- name: (INSTALL) Download client binary
|
|
ansible.builtin.get_url:
|
|
url: '{{ restic_url }}'
|
|
dest: '{{ restic_download_path }}/restic.bz2'
|
|
force: true
|
|
mode: 0644
|
|
register: get_url_restic
|
|
|
|
# TODO: This needs to become independent of the shell module to actually work
|
|
- name: (INSTALL) Decompress the binary
|
|
ansible.builtin.shell: "bzip2 -dc {{ get_url_restic.dest }} > {{ restic_bin_bath }}"
|
|
args:
|
|
creates: '{{ restic_download_path }}/bin/restic-{{ restic_version }}'
|
|
|
|
- name: (INSTALL) Ensure permissions are correct
|
|
ansible.builtin.file:
|
|
path: '{{ restic_download_path }}/bin/restic-{{ restic_version }}'
|
|
mode: '0755'
|
|
owner: '{{ restic_dir_owner }}'
|
|
group: '{{ restic_dir_group }}'
|
|
|
|
- name: (INSTALL) Test the binary
|
|
ansible.builtin.command: "{{ restic_bin_bath }} version"
|
|
ignore_errors: true
|
|
register: restic_test_result
|
|
changed_when: false
|
|
|
|
- name: (INSTALL) Remove faulty binary
|
|
ansible.builtin.file:
|
|
path: '{{ restic_bin_bath }}'
|
|
state: absent
|
|
when: "'FAILED' in restic_test_result.stderr"
|
|
|
|
- name: (INSTALL) Fail if restic could not be installed
|
|
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"
|
|
|
|
- name: (INSTALL) Create symbolic link to the correct version
|
|
ansible.builtin.file:
|
|
src: '{{ restic_download_path }}/bin/restic-{{ restic_version }}'
|
|
path: '{{ restic_install_path }}/restic'
|
|
state: link
|
|
force: true
|
|
rescue:
|
|
- name: (INSTALL) try restic self-update
|
|
become: true
|
|
ansible.builtin.command: "{{ restic_install_path }}/restic self-update"
|
|
changed_when: true
|