From b64bc44b57bfeb60542b0028324202b6f32401e9 Mon Sep 17 00:00:00 2001 From: Frank Dornheim <524257+conloos@users.noreply.github.com> Date: Sun, 5 Mar 2023 14:02:09 +0100 Subject: [PATCH] restructure role add import logic --- tasks/main.yml | 102 ++++--------------------------------------------- 1 file changed, 7 insertions(+), 95 deletions(-) mode change 100755 => 100644 tasks/main.yml diff --git a/tasks/main.yml b/tasks/main.yml old mode 100755 new mode 100644 index 55662ad..674b9bf --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,96 +1,8 @@ --- -- name: Ensure legacy hooks aren't used - ansible.builtin.assert: - that: - - borgmatic_failure_command is undefined - - borgmatic_before_backup_command is undefined - - borgmatic_after_backup_command is undefined - msg: Please use the new borgmatic_hooks variable instead of individual before/after/failure hooks. - -- name: Include OS-specific variables - include_vars: "{{ item }}" - with_first_found: - - "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml" - - "{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml" - - "{{ ansible_distribution }}.yml" - - "{{ ansible_os_family }}.yml" - - "{{ ansible_lsb.id }}.yml" - -- name: Install general dependencies (cron and openssh) - ansible.builtin.package: - name: "{{ borg_dep_packages }}" - state: present - -- name: Install Borg and Borgmatic - ansible.builtin.include_tasks: - file: install_{{ borg_install_method }}.yml - -- name: Ensure root has SSH key. - ansible.builtin.user: - name: "root" - generate_ssh_key: yes - ssh_key_file: "{{ ssh_key_file }}" - ssh_key_type: ed25519 - register: root_user - -- name: Print key created for root user (use for remote repo) - ansible.builtin.debug: - var: root_user['ssh_public_key'] - -- name: Ensure /etc/borgmatic exists - ansible.builtin.file: - path: /etc/borgmatic - state: directory - mode: 0700 - owner: root - -- name: Add Borgmatic configuration - ansible.builtin.template: - src: config.yaml.j2 - dest: "/etc/borgmatic/{{ borgmatic_config_name }}" - mode: 0600 - -- name: Add cron-job for borgmatic (large repo, create and check separate) - block: - - name: Add cron job for regular create and prune - ansible.builtin.cron: - name: "{{ borgmatic_cron_name }}" - hour: "{{ borgmatic_cron_hour }}" - minute: "{{ borgmatic_cron_minute }}" - user: "root" - cron_file: "{{ borgmatic_cron_name }}" - job: "borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} -C -p" - - name: Add cron job for infrequent checks - ansible.builtin.cron: - name: "{{ borgmatic_cron_name }}-check" - day: "{{ borgmatic_cron_checks_day }}" - hour: "{{ borgmatic_cron_checks_hour }}" - minute: "{{ borgmatic_cron_checks_minute }}" - user: "root" - cron_file: "{{ borgmatic_cron_name }}" - job: "borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} -k" - when: borgmatic_large_repo - -- name: Add cron-job for borgmatic (normal-sized repo) - block: - - name: Add cron job for create, check and prune - ansible.builtin.cron: - name: "{{ borgmatic_cron_name }}" - hour: "{{ borgmatic_cron_hour }}" - minute: "{{ borgmatic_cron_minute }}" - user: "root" - cron_file: "{{ borgmatic_cron_name }}" - job: "borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }}" - - name: Ensure separate check cron job is absent - ansible.builtin.cron: - name: "{{ borgmatic_cron_name }}-check" - state: absent - when: not borgmatic_large_repo - -- name: Set PATH for borgmatic cron job. - ansible.builtin.cron: - user: "root" - cron_file: "{{ borgmatic_cron_name }}" - name: PATH - env: yes - value: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin +- name: Add and run all plays + include_tasks: "{{ element }}" + with_items: "{{ lookup( 'ansible.builtin.fileglob', '*.yml' ).split(',') | reject('search', 'main.yml') | reject('search', 'noauto_*') | sort }}" + loop_control: + loop_var: element + tags: always +...