mirror of
https://github.com/roles-ansible/ansible_role_restic.git
synced 2024-12-11 23:41:32 +01:00
add basic versionscheck and split role into better parts
This commit is contained in:
parent
2651b07aed
commit
372c7ce57b
7 changed files with 81 additions and 25 deletions
|
@ -12,3 +12,6 @@ restic_create_cron: false
|
||||||
|
|
||||||
restic_dir_owner: '{{ ansible_user | default(ansible_user_id) }}'
|
restic_dir_owner: '{{ ansible_user | default(ansible_user_id) }}'
|
||||||
restic_dir_group: '{{ 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
|
||||||
|
|
|
@ -4,7 +4,7 @@ galaxy_info:
|
||||||
author: do1jlr
|
author: do1jlr
|
||||||
description: Ansible role to deploy restic and setup backups.
|
description: Ansible role to deploy restic and setup backups.
|
||||||
license: MIT
|
license: MIT
|
||||||
min_ansible_version: 2.9
|
min_ansible_version: 2.10.6
|
||||||
platforms:
|
platforms:
|
||||||
- name: Debian
|
- name: Debian
|
||||||
versions: all
|
versions: all
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
group: '{{ restic_dir_group }}'
|
group: '{{ restic_dir_group }}'
|
||||||
|
|
||||||
- name: Test the binary
|
- name: Test the binary
|
||||||
shell: "{{ restic_bin_bath }} version"
|
ansible.builtin.command: "{{ restic_bin_bath }} version"
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: restic_test_result
|
register: restic_test_result
|
||||||
|
|
||||||
|
|
|
@ -2,34 +2,22 @@
|
||||||
- name: add OS specific variables
|
- name: add OS specific variables
|
||||||
ansible.builtin.include_vars: "{{ lookup('first_found', restic_os_variables) }}"
|
ansible.builtin.include_vars: "{{ lookup('first_found', restic_os_variables) }}"
|
||||||
|
|
||||||
- name: Ensure restic directories exist
|
- name: perform versionscheck
|
||||||
file:
|
ansible.builtin.include_tasks: versioncheck.yml
|
||||||
state: 'directory'
|
when: submodules_versioncheck|bool
|
||||||
path: '{{ item }}'
|
|
||||||
mode: '0755'
|
|
||||||
owner: '{{ restic_dir_owner }}'
|
|
||||||
group: '{{ restic_dir_group }}'
|
|
||||||
with_items: '{{ restic_create_paths }}'
|
|
||||||
|
|
||||||
- name: Check if downloaded binary is present
|
- name: make sure restic is available
|
||||||
stat:
|
ansible.builtin.include_tasks: preperation.yml
|
||||||
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: Install restic
|
- name: Install restic
|
||||||
include: 'install.yml'
|
ansible.builtin.include_tasks: 'install.yml'
|
||||||
when: not restic_executable.stat.exists or not restic_installed.stat.exists
|
when: not restic_executable.stat.exists or not restic_installed.stat.exists
|
||||||
|
|
||||||
- name: Configure restic
|
- name: Configure restic
|
||||||
include: 'configure.yml'
|
ansible.builtin.include_tasks: 'configure.yml'
|
||||||
|
|
||||||
- name: include distribution tasks
|
- name: include distribution tasks
|
||||||
include_tasks: '{{ loop_distribution }}'
|
ansible.builtin.include_tasks: '{{ loop_distribution }}'
|
||||||
with_first_found:
|
with_first_found:
|
||||||
- files:
|
- files:
|
||||||
- '{{ distribution }}-{{ distribution_version }}.yml'
|
- '{{ distribution }}-{{ distribution_version }}.yml'
|
||||||
|
@ -46,6 +34,3 @@
|
||||||
distribution: '{{ ansible_distribution }}'
|
distribution: '{{ ansible_distribution }}'
|
||||||
distribution_version: '{{ ansible_distribution_version }}'
|
distribution_version: '{{ ansible_distribution_version }}'
|
||||||
distribution_major_version: '{{ ansible_distribution_major_version }}'
|
distribution_major_version: '{{ ansible_distribution_major_version }}'
|
||||||
tags:
|
|
||||||
- configuration
|
|
||||||
- packages
|
|
||||||
|
|
19
tasks/preperation.yml
Normal file
19
tasks/preperation.yml
Normal file
|
@ -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
|
46
tasks/versioncheck.yml
Normal file
46
tasks/versioncheck.yml
Normal file
|
@ -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
|
|
@ -9,3 +9,6 @@ restic_os_variables:
|
||||||
- 'defaults.yml'
|
- 'defaults.yml'
|
||||||
paths:
|
paths:
|
||||||
- 'vars'
|
- 'vars'
|
||||||
|
|
||||||
|
playbook_version_number: 3 # should be int
|
||||||
|
playbook_version_path: 'do1jlr.restic.version'
|
||||||
|
|
Loading…
Reference in a new issue