diff --git a/defaults/main.yml b/defaults/main.yml index 3852dd2..4b7ce5d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,8 +1,13 @@ --- # defaults file for skeleton +restic_url: '' restic_version: '0.9.5' -restic_install_dir: '/usr/bin' +restic_download_path: '/opt/restic' +restic_install_path: '/usr/bin' restic_script_dir: '~/restic' restic_repos: {} restic_backups: [] -restic_create_cron: false \ No newline at end of file +restic_create_cron: false + +restic_dir_owner: '{{ansible_user}}' +restic_dir_group: '{{ansible_user}}' \ No newline at end of file diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..ad310da --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,32 @@ +--- +- name: Set restic_url + set_fact: + restic_url: 'https://github.com/restic/restic/releases/download/v{{ restic_version }}/restic_{{ restic_version }}_{{ ansible_system | lower }}_{{ _platform_map[ansible_architecture] | default(ansible_architecture) }}.bz2' + when: restic_url == '' + +- name: Download client binary + get_url: + url: '{{ restic_url }}' + dest: '{{ restic_download_path }}/restic.bz2' + force: True + register: get_url_restic + +# TODO: This needs to become independent of the shell module to actually work on every system +- name: Decompress the binary + shell: "bzip2 -dc {{ get_url_restic.dest }} > {{ restic_download_path }}/bin/restic-{{ restic_version }}" + args: + creates: '{{ restic_download_path }}/bin/restic-{{ restic_version }}' + +- name: Ensure permissions are correct + file: + path: '{{ restic_download_path }}/bin/restic-{{ restic_version }}' + mode: '0755' + owner: '{{ restic_dir_owner }}' + group: '{{ restic_dir_group }}' + +- name: Create symbolic link to the correct version + file: + src: '{{ restic_download_path }}/bin/restic-{{ restic_version }}' + path: '{{ restic_install_path }}/restic' + state: link + force: True \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..219a7ba --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,58 @@ +--- +# tasks file for skeleton + +- name: add OS specific variables + include_vars: '{{ loop_vars }}' + with_first_found: + - files: + - '{{ distribution }}-{{ distribution_version }}.yml' + - '{{ distribution }}-{{ distribution_major_version }}.yml' + - '{{ distribution }}.yml' + - '{{ ansible_os_family }}.yml' + - '{{ ansible_system }}.yml' + - 'defaults.yml' + paths: + - 'vars' + loop_control: + loop_var: loop_vars + vars: + distribution: '{{ ansible_distribution }}' + distribution_version: '{{ ansible_distribution_version }}' + distribution_major_version: '{{ ansible_distribution_major_version }}' + tags: + - configuration + - packages + +- name: Ensure restic directories exist + file: + state: 'directory' + path: '{{ item }}' + mode: '0755' + owner: '{{ restic_dir_owner }}' + group: '{{ restic_dir_group }}' + with_items: '{{ restic_create_paths }}' + +- name: Install restic + include: 'install.yml' + +- name: include distribution tasks + include_tasks: '{{ loop_distribution }}' + with_first_found: + - files: + - '{{ distribution }}-{{ distribution_version }}.yml' + - '{{ distribution }}-{{ distribution_major_version }}.yml' + - '{{ distribution }}.yml' + - '{{ ansible_os_family }}.yml' + - '{{ ansible_system }}.yml' + - 'defaults.yml' + paths: + - 'distribution' + loop_control: + loop_var: loop_distribution + vars: + distribution: '{{ ansible_distribution }}' + distribution_version: '{{ ansible_distribution_version }}' + distribution_major_version: '{{ ansible_distribution_major_version }}' + tags: + - configuration + - packages diff --git a/vars/defaults.yml b/vars/defaults.yml new file mode 100644 index 0000000..87d0d27 --- /dev/null +++ b/vars/defaults.yml @@ -0,0 +1,11 @@ +--- +# we use a platform map to decipher system version +_platform_map: + i386: 386 + x86_64: amd64 + aarch64: arm64 + armv7l: arm + armv6l: arm + +restic_create_paths: + - '{{ restic_install_path }}/bin' \ No newline at end of file