- name: Create Backup Service
  hosts: all
  vars_files:
    - secrets/vars.yaml
  tasks:
  - name: Create /usr/local/script dir
    ansible.builtin.file:
      path: /usr/local/script
      state: directory
      mode: '0755'
  - name: Copy borg-backup.service
    template:
      src: backup.service
      dest: /etc/systemd/system/borg-backup.service
      owner: root
      group: root
      mode: '0644'
  - name: Copy borg-backup.timer
    template:
      src: backup.timer
      dest: /etc/systemd/system/borg-backup.timer
      owner: root
      group: root
      mode: '0644'
  - name: Template borg-backup.sh
    template:
      src: backup.sh.j2
      dest: /usr/local/script/borg-backup.sh
      owner: root
      group: root
      mode: '0744'
  - name: Initialize Repo {{ borg_user }}@{{ borg_host }}:.
    script: /usr/bin/borg init -e none {{ borg_user }}@{{ borg_host }}:.
    ignore_errors: yes
  - name: Reload backup timer borg-backup.timer
    ansible.builtin.systemd_service:
      name: borg-backup.timer
      enabled: true
      daemon_reload: true
