1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_restic.git synced 2024-12-11 23:41:32 +01:00
ansible_role_restic/tasks/install.yml

52 lines
1.8 KiB
YAML
Raw Normal View History

2019-08-13 13:26:40 +02:00
---
2021-08-03 23:16:34 +02:00
- name: install and verify restic binary
block:
- name: Download client binary
ansible.builtin.get_url:
url: '{{ restic_url }}'
dest: '{{ restic_download_path }}/restic.bz2'
force: true
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
- name: Decompress the binary
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
2021-08-03 23:16:34 +02:00
- name: 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 }}'
2019-08-13 13:26:40 +02:00
2021-08-03 23:16:34 +02:00
- name: Test the binary
ansible.builtin.command: "{{ restic_bin_bath }} version"
ignore_errors: true
register: restic_test_result
2021-08-03 23:16:34 +02:00
- name: Remove faulty binary
ansible.builtin.file:
path: '{{ restic_bin_bath }}'
state: absent
when: "'FAILED' in restic_test_result.stderr"
2021-08-03 23:16:34 +02:00
- name: 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"
2021-08-03 23:16:34 +02:00
- name: 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: try restic self-update
become: true
ansible.builtin.command: "{{ restic_install_path }}/restic self-update"