diff --git a/defaults/main.yml b/defaults/main.yml index 6ca6be5..8caf7b9 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -4,6 +4,7 @@ borg_exclude_patterns: [] borg_one_file_system: true borg_exclude_from: [] borg_encryption_passcommand: false +borg_key_export_path: "~/{{ borg_repository }}.key" borg_lock_wait_time: 5 borg_ssh_key_file_path: "/root/.ssh/{{ borg_ssh_key_name }}" borg_ssh_key_name: borgbackup diff --git a/tasks/borgmatic.yml b/tasks/borgmatic.yml new file mode 100644 index 0000000..b81ca25 --- /dev/null +++ b/tasks/borgmatic.yml @@ -0,0 +1,31 @@ +--- +- name: "Borgamtic | Copy configuration" + ansible.builtin.template: + src: config.yaml.j2 + dest: "/etc/borgmatic/{{ borgmatic_config_name }}" + mode: "0600" + +- name: "Borgmatic | Add cron job" + ansible.builtin.cron: + name: "{{ borgmatic_timer_cron_name }}" + hour: "{{ borgmatic_timer_hour }}" + minute: "{{ borgmatic_timer_minute }}" + user: "{{ borg_user }}" + cron_file: "{{ borgmatic_timer_cron_name }}" + job: "borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }}" + +- name: "Borgmatic | Init borg repository" + ansible.builtin.expect: + command: "borgmatic init -e {{ borg_repo_key }}" + responses: + ^.*want to continue connecting.*$: "yes" + +- name: "Borgmatic | Create backup" + ansible.builtin.command: + cmd: "borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }}" + +- name: "Borgmatic | Export repo key" + ansible.builtin.command: + cmd: "borg key export {{ item }} > {{ borg_key_export_path }}" + loop: "{{ borg_repository }}" + delegate_to: localhost diff --git a/tasks/main.yml b/tasks/main.yml index a0c8e6c..c0fd931 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -12,24 +12,6 @@ when: borgbase is defined and borgbase tags: borgbase -- name: Copy borgmatic configuration - ansible.builtin.template: - src: config.yaml.j2 - dest: "/etc/borgmatic/{{ borgmatic_config_name }}" - mode: "0600" - -- name: Add single Cron job for borgmatic - ansible.builtin.cron: - name: "{{ borgmatic_timer_cron_name }}" - hour: "{{ borgmatic_timer_hour }}" - minute: "{{ borgmatic_timer_minute }}" - user: "{{ borg_user }}" - cron_file: "{{ borgmatic_timer_cron_name }}" - job: "borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }}" - -- name: Init repo - ansible.builtin.expect: - command: "borgmatic init -e {{ borg_repo_key }}" - responses: - ^.*want to continue connecting.*$: "yes" - +- name: Setup borgmatic + ansible.builtin.import_tasks: borgmatic.yml + tags: borgmatic