1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_restic.git synced 2024-12-11 23:41:32 +01:00

Adding task name prefix to task

This commit is contained in:
L3D 2022-01-10 14:19:53 +01:00
parent 9b8962cc5f
commit 75e78c5876
Signed by: l3d
GPG key ID: CD08445BFF4313D1
12 changed files with 39 additions and 39 deletions

View file

@ -1,11 +1,11 @@
--- ---
- name: reformat dict if necessary - name: (BACKUP) reformat dict if necessary
set_fact: set_fact:
restic_backups: "{{ restic_backups|dict2items|json_query('[*].value') }}" restic_backups: "{{ restic_backups|dict2items|json_query('[*].value') }}"
when: when:
- restic_backups | type_debug == "dict" - restic_backups | type_debug == "dict"
- name: Create backup credentials - name: (BACKUP) Create backup credentials
template: template:
src: restic_access_Linux.j2 src: restic_access_Linux.j2
dest: "{{ restic_script_dir }}/access-{{ item.name | replace(' ', '') }}.sh" dest: "{{ restic_script_dir }}/access-{{ item.name | replace(' ', '') }}.sh"
@ -20,7 +20,7 @@
- item.src is defined or item.stdin and item.stdin_cmd is defined - item.src is defined or item.stdin and item.stdin_cmd is defined
- item.repo in restic_repos - item.repo in restic_repos
- name: Create backup script - name: (BACKUP) Create backup script
template: template:
src: restic_script_Linux.j2 src: restic_script_Linux.j2
dest: "{{ restic_script_dir }}/backup-{{ item.name | replace(' ', '') }}.sh" dest: "{{ restic_script_dir }}/backup-{{ item.name | replace(' ', '') }}.sh"

View file

@ -1,5 +1,5 @@
--- ---
- name: Initialize repository - name: (CONF)Initialize repository
command: '{{ restic_install_path }}/restic init' command: '{{ restic_install_path }}/restic init'
environment: environment:
RESTIC_REPOSITORY: '{{ item.value.location }}' RESTIC_REPOSITORY: '{{ item.value.location }}'

View file

@ -1,5 +1,5 @@
--- ---
- name: "check if ansible version is under 2.12.0" - name: "(SCHEDULE) (OLD) check if ansible version is under 2.12.0"
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- "ansible_version.full is version_compare('2.12.0', '<')" - "ansible_version.full is version_compare('2.12.0', '<')"
@ -7,7 +7,7 @@
success_msg: "Congratulations. You are using ansible version {{ ansible_version.full }}" success_msg: "Congratulations. You are using ansible version {{ ansible_version.full }}"
delegate_to: localhost delegate_to: localhost
- name: try to remove entries from /etc/crontab - name: (SCHEDULE) (OLD) try to remove entries from /etc/crontab
ansible.builtin.cron: ansible.builtin.cron:
name: "do1jlr.restic backup {{ item.name }}" name: "do1jlr.restic backup {{ item.name }}"
job: "CRON=true {{ restic_script_dir }}/backup-{{ item.name | replace(' ', '') }}.sh" job: "CRON=true {{ restic_script_dir }}/backup-{{ item.name | replace(' ', '') }}.sh"
@ -29,7 +29,7 @@
ignore_error: true ignore_error: true
register: cron_delete register: cron_delete
- name: "make sure 'do1jlr.restic backup {{ item.name }}' is not in /etc/crontab" - name: "(SCHEDULE) (OLD) make sure 'do1jlr.restic backup {{ item.name }}' is not in /etc/crontab"
become: true become: true
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: '/etc/crontab' path: '/etc/crontab'
@ -38,7 +38,7 @@
when: cron_delete.failed when: cron_delete.failed
with_items: '{{ restic_backups }}' with_items: '{{ restic_backups }}'
- name: "make sure '{{ restic_script_dir }}/backup-{{ item.name | replace(' ', '') }}.sh' is not in /etc/crontab" - name: "(SCHEDULE) (OLD) make sure '{{ restic_script_dir }}/backup-{{ item.name | replace(' ', '') }}.sh' is not in /etc/crontab"
become: true become: true
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: '/etc/crontab' path: '/etc/crontab'

View file

@ -2,5 +2,5 @@
# tasks file for skeleton # tasks file for skeleton
- name: Message - name: Message
debug: ansible.builtin.fail:
msg: 'Your {{ ansible_system }} is not yet supported' msg: 'Your {{ ansible_system }} is not yet supported'

View file

@ -1,8 +1,8 @@
--- ---
- name: install and verify restic binary - name: (INSTALL) install and verify restic binary
become: true become: true
block: block:
- name: Download client binary - name: (INSTALL) Download client binary
ansible.builtin.get_url: ansible.builtin.get_url:
url: '{{ restic_url }}' url: '{{ restic_url }}'
dest: '{{ restic_download_path }}/restic.bz2' dest: '{{ restic_download_path }}/restic.bz2'
@ -10,43 +10,43 @@
register: get_url_restic register: get_url_restic
# TODO: This needs to become independent of the shell module to actually work # TODO: This needs to become independent of the shell module to actually work
- name: Decompress the binary - name: (INSTALL) Decompress the binary
ansible.builtin.shell: "bzip2 -dc {{ get_url_restic.dest }} > {{ restic_bin_bath }}" ansible.builtin.shell: "bzip2 -dc {{ get_url_restic.dest }} > {{ restic_bin_bath }}"
args: args:
creates: '{{ restic_download_path }}/bin/restic-{{ restic_version }}' creates: '{{ restic_download_path }}/bin/restic-{{ restic_version }}'
- name: Ensure permissions are correct - name: (INSTALL) Ensure permissions are correct
ansible.builtin.file: ansible.builtin.file:
path: '{{ restic_download_path }}/bin/restic-{{ restic_version }}' path: '{{ restic_download_path }}/bin/restic-{{ restic_version }}'
mode: '0755' mode: '0755'
owner: '{{ restic_dir_owner }}' owner: '{{ restic_dir_owner }}'
group: '{{ restic_dir_group }}' group: '{{ restic_dir_group }}'
- name: Test the binary - name: (INSTALL) Test the binary
ansible.builtin.command: "{{ 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
- name: Remove faulty binary - name: (INSTALL) Remove faulty binary
ansible.builtin.file: ansible.builtin.file:
path: '{{ restic_bin_bath }}' path: '{{ restic_bin_bath }}'
state: absent state: absent
when: "'FAILED' in restic_test_result.stderr" when: "'FAILED' in restic_test_result.stderr"
- name: Fail if restic could not be installed - name: (INSTALL) Fail if restic could not be installed
ansible.builtin.fail: ansible.builtin.fail:
msg: >- msg: >-
Restic binary has been faulty and has been removed. Restic binary has been faulty and has been removed.
Try to re-run the role and make sure you have bzip2 installed! Try to re-run the role and make sure you have bzip2 installed!
when: "'FAILED' in restic_test_result.stderr" when: "'FAILED' in restic_test_result.stderr"
- name: Create symbolic link to the correct version - name: (INSTALL) Create symbolic link to the correct version
ansible.builtin.file: ansible.builtin.file:
src: '{{ restic_download_path }}/bin/restic-{{ restic_version }}' src: '{{ restic_download_path }}/bin/restic-{{ restic_version }}'
path: '{{ restic_install_path }}/restic' path: '{{ restic_install_path }}/restic'
state: link state: link
force: true force: true
rescue: rescue:
- name: try restic self-update - name: (INSTALL) try restic self-update
become: true become: true
ansible.builtin.command: "{{ restic_install_path }}/restic self-update" ansible.builtin.command: "{{ restic_install_path }}/restic self-update"

View file

@ -1,5 +1,5 @@
--- ---
- name: Ensure restic directories exist - name: (PREPARE) Ensure restic directories exist
become: true become: true
ansible.builtin.file: ansible.builtin.file:
state: 'directory' state: 'directory'
@ -9,12 +9,12 @@
group: '{{ restic_dir_group }}' group: '{{ restic_dir_group }}'
with_items: '{{ restic_create_paths }}' with_items: '{{ restic_create_paths }}'
- name: Check if downloaded binary is present - name: (PREPARE) Check if downloaded binary is present
ansible.builtin.stat: ansible.builtin.stat:
path: '{{ restic_download_path }}/bin/restic-{{ restic_version }}' path: '{{ restic_download_path }}/bin/restic-{{ restic_version }}'
register: restic_executable register: restic_executable
- name: Check if installed binary is present - name: (PREPARE) Check if installed binary is present
ansible.builtin.stat: ansible.builtin.stat:
path: '{{ restic_install_path }}/restic' path: '{{ restic_install_path }}/restic'
register: restic_installed register: restic_installed

View file

@ -1,5 +1,5 @@
--- ---
- name: install restic backup cronjob - name: (SCHEDULE) (CRON) install restic backup cronjob
ansible.builtin.cron: ansible.builtin.cron:
name: "do1jlr.restic backup {{ item.name }}" name: "do1jlr.restic backup {{ item.name }}"
job: "CRON=true {{ restic_script_dir }}/backup-{{ item.name | replace(' ', '') }}.sh" job: "CRON=true {{ restic_script_dir }}/backup-{{ item.name | replace(' ', '') }}.sh"

View file

@ -1,7 +1,7 @@
--- ---
- name: create systemd timer - name: (SCHEDULE) (SYSTEMD) create systemd timer
block: block:
- name: copy systemd timer - name: (SCHEDULE) (SYSTEMD) copy systemd timer
become: true become: true
ansible.builtin.template: ansible.builtin.template:
src: templates/restic.timer.j2 src: templates/restic.timer.j2
@ -16,7 +16,7 @@
- item.name is defined - item.name is defined
- item.scheduled | default(false) - item.scheduled | default(false)
- name: copy systemd service - name: (SCHEDULE) (SYSTEMD) copy systemd service
become: true become: true
ansible.builtin.template: ansible.builtin.template:
src: templates/restic.service.j2 src: templates/restic.service.j2
@ -30,7 +30,7 @@
- item.name is defined - item.name is defined
- item.scheduled | default(false) - item.scheduled | default(false)
- name: Enable restic service - name: (SCHEDULE) (SYSTEMD) Enable restic service
become: true become: true
ansible.builtin.systemd: ansible.builtin.systemd:
name: "restic-{{ item.name | replace(' ', '') | string }}.service" name: "restic-{{ item.name | replace(' ', '') | string }}.service"
@ -43,7 +43,7 @@
- item.name is defined - item.name is defined
- item.scheduled | default(false) - item.scheduled | default(false)
- name: Enable and start restic timer - name: (SCHEDULE) (SYSTEMD) Enable and start restic timer
become: true become: true
ansible.builtin.systemd: ansible.builtin.systemd:
name: "restic-{{ item.name | replace(' ', '') | string }}.timer" name: "restic-{{ item.name | replace(' ', '') | string }}.timer"

View file

@ -1,5 +1,5 @@
--- ---
- name: remove restic backup cronjob - name: (SCHEDULE) (CRON) remove restic backup cronjob
ansible.builtin.cron: ansible.builtin.cron:
name: "do1jlr.restic backup {{ item.name }}" name: "do1jlr.restic backup {{ item.name }}"
job: "CRON=true {{ restic_script_dir }}/backup-{{ item.name | replace(' ', '') }}.sh" job: "CRON=true {{ restic_script_dir }}/backup-{{ item.name | replace(' ', '') }}.sh"

View file

@ -1,7 +1,7 @@
--- ---
- name: remove systemd timer - name: (SCHEDULE) (SYSTEMD) remove systemd timer
block: block:
- name: mask restic timer - name: (SCHEDULE) (SYSTEMD) mask restic timer
become: true become: true
ansible.builtin.systemd: ansible.builtin.systemd:
name: "restic-{{ item.name | replace(' ', '') | string }}.timer" name: "restic-{{ item.name | replace(' ', '') | string }}.timer"
@ -18,7 +18,7 @@
- item.scheduled | default(false) - item.scheduled | default(false)
- restic_schedule_type == "cronjob" or restic_force_cron | default(false) - restic_schedule_type == "cronjob" or restic_force_cron | default(false)
- name: mask restic service - name: (SCHEDULE) (SYSTEMD) mask restic service
become: true become: true
ansible.builtin.systemd: ansible.builtin.systemd:
name: "restic-{{ item.name | replace(' ', '') | string }}.service" name: "restic-{{ item.name | replace(' ', '') | string }}.service"
@ -35,7 +35,7 @@
failed_when: false failed_when: false
changed_when: false changed_when: false
- name: delete systemd .timer file - name: (SCHEDULE) (SYSTEMD) delete systemd .timer file
become: true become: true
ansible.builtin.file: ansible.builtin.file:
path: "/lib/systemd/system/restic-{{ item.name | replace(' ', '') }}.timer" path: "/lib/systemd/system/restic-{{ item.name | replace(' ', '') }}.timer"
@ -46,7 +46,7 @@
- item.scheduled | default(false) - item.scheduled | default(false)
- restic_schedule_type == "cronjob" or restic_force_cron | default(false) - restic_schedule_type == "cronjob" or restic_force_cron | default(false)
- name: delete systemd .service file - name: (SCHEDULE) (SYSTEMD) delete systemd .service file
become: true become: true
ansible.builtin.file: ansible.builtin.file:
path: "/lib/systemd/system/restic-{{ item.name | replace(' ', '') }}.service" path: "/lib/systemd/system/restic-{{ item.name | replace(' ', '') }}.service"

View file

@ -1,29 +1,29 @@
--- ---
- name: create restic systemd timer - name: (SCHEDULE) create restic systemd timer
ansible.builtin.include_tasks: restic_create_systemd.yml ansible.builtin.include_tasks: restic_create_systemd.yml
when: when:
- ansible_service_mgr == 'systemd' - ansible_service_mgr == 'systemd'
- restic_schedule_type == "systemd" - restic_schedule_type == "systemd"
- restic_create_schedule | bool - restic_create_schedule | bool
- name: delete systemd timers if available - name: (SCHEDULE) delete systemd timers if available
ansible.builtin.include_tasks: restic_delete_systemd.yml ansible.builtin.include_tasks: restic_delete_systemd.yml
when: when:
- ansible_service_mgr == 'systemd' - ansible_service_mgr == 'systemd'
- restic_schedule_type == "cronjob" or restic_force_cron | default(false) - restic_schedule_type == "cronjob" or restic_force_cron | default(false)
- restic_create_schedule | bool - restic_create_schedule | bool
- name: delete old cron entry from previous versions of this role - name: (SCHEDULE) delete old cron entry from previous versions of this role
ansible.builtin.include_tasks: delete_legacy_cron_entry.yml ansible.builtin.include_tasks: delete_legacy_cron_entry.yml
when: restic_do_not_cleanup_cron | bool when: restic_do_not_cleanup_cron | bool
- name: install restic via cronjob - name: (SCHEDULE) install restic via cronjob
ansible.builtin.include_tasks: restic_create_cron.yml ansible.builtin.include_tasks: restic_create_cron.yml
when: when:
- restic_create_schedule | bool - restic_create_schedule | bool
- ansible_service_mgr != 'systemd' or restic_force_cron | default(false) or restic_schedule_type == "cronjob" - ansible_service_mgr != 'systemd' or restic_force_cron | default(false) or restic_schedule_type == "cronjob"
- name: remove restic cronjobs - name: (SCHEDULE) remove restic cronjobs
ansible.builtin.include_tasks: restic_delete_cron.yml ansible.builtin.include_tasks: restic_delete_cron.yml
when: when:
- restic_create_schedule | bool - restic_create_schedule | bool

View file

@ -10,5 +10,5 @@ restic_os_variables:
paths: paths:
- 'vars' - 'vars'
playbook_version_number: 21 # should be int playbook_version_number: 22 # should be int
playbook_version_path: 'do1jlr.restic.version' playbook_version_path: 'do1jlr.restic.version'