---
- name: Sync Configuration Files
  hosts: borg_servers
  become: yes

  tasks:
  - name: Borg group
    ansible.builtin.group:
      name: borg
      state: present
      system: true

  - name: Borg User
    ansible.builtin.user:
      name: borg
      group: borg
      comment: Borg Service
      create_home: yes
      system: true

  - name: Install borg
    package:
      name: "borgbackup"
      state: present

  - name: Ensure borg .ssh directory
    ansible.builtin.file:
      path: /home/borg/.ssh
      state: directory
      owner: borg
      group: borg
      mode: '0700'

  - name: concat
    ansible.builtin.assemble:
      src: authorized_keys
      dest: /home/borg/.ssh/authorized_keys
      owner: borg
      group: borg
      mode: '0600'
      remote_src: false

  - name: Make backup directories
    file:
      path: /var/borg/{{ item | basename }}
      state: directory
      owner: borg
      group: borg
      mode: '0700'

    with_fileglob:
      - "authorized_keys/*"


