From 1c423fb74239105e8b6fd2d5ef1f1709b730f16d Mon Sep 17 00:00:00 2001 From: Lilian Roller Date: Wed, 9 Dec 2020 14:36:46 +0100 Subject: [PATCH] update archiver f00 --- tasks/distribution/defaults.yml | 6 ---- tasks/main.yml | 44 ++++++++++++++------------- tasks/template.yml | 54 +++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 27 deletions(-) delete mode 100644 tasks/distribution/defaults.yml create mode 100644 tasks/template.yml diff --git a/tasks/distribution/defaults.yml b/tasks/distribution/defaults.yml deleted file mode 100644 index 8eb12ce..0000000 --- a/tasks/distribution/defaults.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -# tasks file for skeleton - -- name: Message - debug: - msg: 'Your {{ ansible_system }} is not supported' diff --git a/tasks/main.yml b/tasks/main.yml index 3551fe1..61f1f96 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,27 +2,29 @@ - include_tasks: versioncheck.yml when: submodules_versioncheck|bool -- 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 +- include_tasks: template.yml + +#- 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: diff --git a/tasks/template.yml b/tasks/template.yml new file mode 100644 index 0000000..9dd78d1 --- /dev/null +++ b/tasks/template.yml @@ -0,0 +1,54 @@ +--- +- name: reformat dict if necessary + set_fact: + restic_archiver__backups: "{{ restic_archiver__backups|dict2items|json_query('[*].value') }}" + when: + - restic_archiver__backups | type_debug == "dict" + +- name: Create backup credentials + template: + src: restic_access_Linux.j2 + dest: '{{ restic_script_dir }}/access-{{ item.name }}.sh' + mode: '0700' + owner: '{{ restic_dir_owner }}' + group: '{{ restic_dir_group }}' + no_log: true + with_items: '{{ restic_archiver__backups }}' + when: + - item.name is defined + - item.src is defined or item.stdin is defined + - item.src is defined or item.stdin and item.stdin_cmd is defined + - item.repo in restic_repos + +- name: Create backup script + template: + src: restic_script_Linux.j2 + dest: '{{ restic_script_dir }}/backup-{{ item.name }}.sh' + mode: '0700' + owner: '{{ restic_dir_owner }}' + group: '{{ restic_dir_group }}' + no_log: true + with_items: '{{ restic_archiver__backups }}' + when: + - item.name is defined + - item.src is defined or item.stdin is defined + - item.src is defined or item.stdin and item.stdin_cmd is defined + - item.repo in restic_repos + +- name: Setup CRON jobs + cron: + name: 'do1jlr.restic_archiver {{ item.name }}' + job: 'CRON=true {{ restic_script_dir }}/backup-{{ item.name }}.sh' + minute: '{{ item.schedule_minute | default("*") }}' + hour: '{{ item.schedule_hour | default("*") }}' + weekday: '{{ item.schedule_weekday | default("*") }}' + month: '{{ item.schedule_month | default("*") }}' + cron_file: '/etc/crontab' + state: present + become: true + no_log: true + with_items: '{{ restic_archiver__backups }}' + when: + - restic_create_cron + - item.name is defined + - item.scheduled | default(false)