--- - name: packages become: yes tags: packages apt: name: "{{ items }}" install_recommends: no vars: items: - borgbackup - name: mkdir /etc/borg become: yes file: path: /etc/borg state: directory mode: u=rwx,go= - name: Generate SSH keys become: yes command: ssh-keygen -t ed25519 -N "" -f "{{ ssh_key }}" -C "for borg @ {{ ansible_hostname }}" args: creates: "{{ ssh_key }}" register: ssh_key_generated - when: ssh_key_generated.changed become: yes fetch: src: "{{ ssh_key }}.pub" dest: "files" - name: /etc/borg/env become: yes copy: dest: /etc/borg/env content: | BORG_REPO="borg@{{ borg_client__server }}:{{ ansible_hostname }}" BORG_RSH="ssh -i {{ ssh_key}}" # " - name: /etc/borg/excludes become: yes when: borg_client__state == "absent" file: path: /etc/borg/excludes state: absent - name: /etc/borg/excludes when: borg_client__state == "present" become: yes copy: dest: /etc/borg/excludes content: | /proc /dev /sys - name: /etc/borg/patterns become: yes copy: dest: /etc/borg/patterns content: | P sh R / {% for item in borg_client__patterns %} {{ item }} {% endfor %} - name: /usr/local/bin/create-backup become: yes template: dest: /usr/local/bin/create-backup src: bin/create-backup mode: u=rx,go= owner: root group: root - become: yes copy: dest: /etc/systemd/system/create-backup.service content: | [Unit] Description=Create backup [Service] Type=oneshot WorkingDirectory=/ ExecStart=/usr/local/bin/create-backup register: create_backup_service - when: create_backup_service.changed become: yes systemd: daemon_reload: yes