diff options
Diffstat (limited to 'tasks')
| -rw-r--r-- | tasks/client_create_scripts_each.yml | 31 | ||||
| -rw-r--r-- | tasks/client_setup.yml | 57 | ||||
| -rw-r--r-- | tasks/installation.yml | 1 |
3 files changed, 65 insertions, 24 deletions
diff --git a/tasks/client_create_scripts_each.yml b/tasks/client_create_scripts_each.yml new file mode 100644 index 0000000..dcf379f --- /dev/null +++ b/tasks/client_create_scripts_each.yml @@ -0,0 +1,31 @@ +--- +- name: Create script for automatic borg backup + ansible.builtin.file: + dest: '{{ script_location }}' + state: touch + owner: root + group: root + modification_time: preserve + access_time: preserve + mode: '0711' + become: true + +- name: Insert shebang into backup script + ansible.builtin.lineinfile: + path: '{{ script_location }}' + line: '#!/bin/bash' + insertbefore: BOF + state: present + become: true + +- name: Insert Backup job block into scripts + ansible.builtin.blockinfile: + path: '{{ script_location }}' + marker: '## {mark} ANSIBLE MANAGED BLOCK for server: {{ borg_server_host_url }}' + block: | + export BORG_PASSPHRASE={{ borg_passphrase }} + borg create -C {{ borg_compression }} \ + borg@{{ borg_server_host_url }}:{{ borg_server_user_home }}/{{ borg_repo_name }}::{{ borg_backup_name_format }} \ + {{ borg_included_dirs | map('quote') | join(' ') }} \ + {% for e in (borg_excluded_dirs | map('quote')) %} --exclude {{ e }} {% endfor %} + become: true diff --git a/tasks/client_setup.yml b/tasks/client_setup.yml index d3e9f75..eb6c9a1 100644 --- a/tasks/client_setup.yml +++ b/tasks/client_setup.yml @@ -92,29 +92,40 @@ delegate_to: localhost become: false -- name: Set up env for cron job - ansible.builtin.cron: - name: BORG_PASSPHRASE - job: '{{ borg_passphrase }}' - state: '{{ "present" if (borg_included_dirs | length > 0) else "absent" }}' - env: true - user: root +- name: Create backup scripts + ansible.builtin.include_tasks: client_create_scripts_each.yml + loop: + - '{{ borg_backup_script_location }}' + - '{{ borg_backup_script_location }}{{ "@" if borg_backup_argument != "" }}{{ borg_backup_argument }}' + loop_control: + loop_var: script_location + +- name: Configure systemd borg_backup service + ansible.builtin.template: + src: borg_backup.service.j2 + dest: /etc/systemd/system/{{ borg_backup_timer_name }}{{ "@" if borg_backup_argument != "" }}{{ borg_backup_argument }}.service + mode: '0644' + owner: root + group: root + notify: Reload systemd + become: true + +- name: Configure systemd borg_backup timer + ansible.builtin.template: + src: borg_backup.timer.j2 + dest: /etc/systemd/system/{{ borg_backup_timer_name }}{{ "@" if borg_backup_argument != "" }}{{ borg_backup_argument }}.timer + mode: '0644' + owner: root + group: root + notify: Reload systemd become: true -- name: Set up backup cron jobs - ansible.builtin.cron: - name: BORG (Application level backups) - job: > - borg create -C {{ borg_compression }} - borg@{{ borg_server_host_url }}:{{ borg_server_user_home }}/{{ borg_repo_name }}::{{ borg_backup_name_format }} - {{ borg_included_dirs | map('quote') | join(' ') }} - {% for e in (borg_excluded_dirs | map('quote')) %} --exclude {{ e }} {% endfor %} - user: root - state: '{{ "present" if (borg_included_dirs | length > 0) else "absent" }}' - minute: '{{ borg_cron_time.minute | default(omit) }}' - hour: '{{ borg_cron_time.hour | default(omit) }}' - weekday: '{{ borg_cron_time.weekday | default(omit) }}' - day: '{{ borg_cron_time.day | default(omit) }}' - month: '{{ borg_cron_time.month | default(omit) }}' - special_time: '{{ borg_cron_time.special_time | default(omit) }}' +- name: Reload systemd now before enabling services + ansible.builtin.meta: flush_handlers + +- name: Enable borg_backup systemd timer + ansible.builtin.systemd: + name: '{{ borg_backup_timer_name }}{{ "@" if borg_backup_argument != "" }}{{ borg_backup_argument }}.timer' + state: started + enabled: true become: true diff --git a/tasks/installation.yml b/tasks/installation.yml index 8ee0835..7e64ff3 100644 --- a/tasks/installation.yml +++ b/tasks/installation.yml @@ -13,7 +13,6 @@ ansible.builtin.apt: name: - borgbackup - - cron - ssh state: present update_cache: true |