diff --git a/defaults/main.yml b/defaults/main.yml index 5d8bdc7..3426d95 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -12,3 +12,6 @@ restic_create_cron: false restic_dir_owner: '{{ ansible_user | default(ansible_user_id) }}' restic_dir_group: '{{ ansible_user | default(ansible_user_id) }}' + +# perform simple version check for this role? (true is recomended) +submodules_versioncheck: false diff --git a/meta/main.yml b/meta/main.yml index f2206db..e959d5e 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -4,7 +4,7 @@ galaxy_info: author: do1jlr description: Ansible role to deploy restic and setup backups. license: MIT - min_ansible_version: 2.9 + min_ansible_version: 2.10.6 platforms: - name: Debian versions: all diff --git a/tasks/install.yml b/tasks/install.yml index 4ce6ea9..c161b0e 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -22,7 +22,7 @@ group: '{{ restic_dir_group }}' - name: Test the binary - shell: "{{ restic_bin_bath }} version" + ansible.builtin.command: "{{ restic_bin_bath }} version" ignore_errors: true register: restic_test_result diff --git a/tasks/main.yml b/tasks/main.yml index 668200f..db5ed5a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,34 +2,22 @@ - name: add OS specific variables ansible.builtin.include_vars: "{{ lookup('first_found', restic_os_variables) }}" -- 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: perform versionscheck + ansible.builtin.include_tasks: versioncheck.yml + when: submodules_versioncheck|bool -- name: Check if downloaded binary is present - stat: - path: '{{ restic_download_path }}/bin/restic-{{ restic_version }}' - register: restic_executable - -- name: Check if installed binary is present - stat: - path: '{{ restic_install_path }}/restic' - register: restic_installed +- name: make sure restic is available + ansible.builtin.include_tasks: preperation.yml - name: Install restic - include: 'install.yml' + ansible.builtin.include_tasks: 'install.yml' when: not restic_executable.stat.exists or not restic_installed.stat.exists - name: Configure restic - include: 'configure.yml' + ansible.builtin.include_tasks: 'configure.yml' - name: include distribution tasks - include_tasks: '{{ loop_distribution }}' + ansible.builtin.include_tasks: '{{ loop_distribution }}' with_first_found: - files: - '{{ distribution }}-{{ distribution_version }}.yml' @@ -46,6 +34,3 @@ distribution: '{{ ansible_distribution }}' distribution_version: '{{ ansible_distribution_version }}' distribution_major_version: '{{ ansible_distribution_major_version }}' - tags: - - configuration - - packages diff --git a/tasks/preperation.yml b/tasks/preperation.yml new file mode 100644 index 0000000..22d58e2 --- /dev/null +++ b/tasks/preperation.yml @@ -0,0 +1,19 @@ +--- +- name: Ensure restic directories exist + ansible.builtin.file: + state: 'directory' + path: '{{ item }}' + mode: '0755' + owner: '{{ restic_dir_owner }}' + group: '{{ restic_dir_group }}' + with_items: '{{ restic_create_paths }}' + +- name: Check if downloaded binary is present + ansible.builtin.stat: + path: '{{ restic_download_path }}/bin/restic-{{ restic_version }}' + register: restic_executable + +- name: Check if installed binary is present + ansible.builtin.stat: + path: '{{ restic_install_path }}/restic' + register: restic_installed diff --git a/tasks/versioncheck.yml b/tasks/versioncheck.yml new file mode 100644 index 0000000..dca3e47 --- /dev/null +++ b/tasks/versioncheck.yml @@ -0,0 +1,46 @@ +--- +- name: Create directory for versionscheck + become: true + ansible.builtin.file: + path: '/etc/.ansible-version' + state: directory + mode: 0755 + when: submodules_versioncheck|bool + +- name: check playbook version + become: true + ansible.builtin.slurp: + src: "/etc/.ansible-version/{{ playbook_version_path }}" + register: playbook_version + when: submodules_versioncheck|bool + ignore_errors: true + failed_when: false + +- name: Print remote role version + ansible.builtin.debug: + msg: "Remote role version: {{ playbook_version.content | default('Y3VycmVudGx5IG5vdCBkZXBsb3llZAo=') | b64decode | string }}" + when: submodules_versioncheck|bool + +- name: Print locale role version + ansible.builtin.debug: + msg: "Local role version: '{{ playbook_version_number|string }}'." + when: submodules_versioncheck|bool + +- name: Check if your version is outdated + ansible.builtin.fail: + msg: "Your ansible module has the version '{{ playbook_version_number }}' and is outdated. You need to update it!" + when: + - playbook_version.content|default("Mgo=")|b64decode|int - 1 >= playbook_version_number|int and submodules_versioncheck|bool + +- name: check if '/etc/ansible-version/' is empty + ansible.builtin.find: + paths: '/etc/ansible-version/' + register: filesFound + +- name: write new version to remote disk + become: true + ansible.builtin.copy: + content: "{{ playbook_version_number }}" + dest: "/etc/.ansible-version/{{ playbook_version_path }}" + mode: '0644' + when: submodules_versioncheck|bool diff --git a/vars/main.yml b/vars/main.yml index 2b8a3bf..4fa0924 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -9,3 +9,6 @@ restic_os_variables: - 'defaults.yml' paths: - 'vars' + +playbook_version_number: 3 # should be int +playbook_version_path: 'do1jlr.restic.version'