From 4d311e57275651c6e4a6f445a729a6939e514b71 Mon Sep 17 00:00:00 2001 From: Matthias Leutenegger Date: Tue, 13 Aug 2019 13:26:40 +0200 Subject: [PATCH] installing binary --- defaults/main.yml | 9 ++++++-- tasks/install.yml | 32 ++++++++++++++++++++++++++ tasks/main.yml | 58 +++++++++++++++++++++++++++++++++++++++++++++++ vars/defaults.yml | 11 +++++++++ 4 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 tasks/install.yml create mode 100644 tasks/main.yml create mode 100644 vars/defaults.yml 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