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_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
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
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'
|
||||
paths:
|
||||
- 'vars'
|
||||
|
||||
playbook_version_number: 3 # should be int
|
||||
playbook_version_path: 'do1jlr.restic.version'
|
||||
|
|
Loading…
Reference in a new issue