- name: Install packages
  package:
    name:
    - borgbackup
    state: present
  tags:
  - weblate_backup

- name: Create a non root user to run the code
  user:
    name: _backup_weblate
  tags:
  - weblate_backup

- name: create a .ssh dir for that user
  file:
    dest: "/home/_backup_weblate/.ssh"
    mode: 0700
    state: directory
    owner: _backup_weblate
    group: _backup_weblate
  tags:
  - weblate_backup

- name: Copy private key
  copy:
    src: "{{ private }}/files/weblate/id_rsa"
    dest: ~_backup_weblate/.ssh/id_rsa
    owner: _backup_weblate
    group: _backup_weblate
    mode: 0600
  tags:
  - weblate_backup

- name: Copy passphrase file
  copy:
    src: "{{ private }}/files/weblate/borg_passphrase"
    dest: ~_backup_weblate/.borgpass
    owner: _backup_weblate
    group: _backup_weblate
    mode: 0600
  tags:
  - weblate_backup
 
- name: Install backup script
  template:
    src: weblate-backup
    dest: /usr/local/bin/weblate-backup
    owner: root
    group: root
    mode: 0755
  tags:
  - weblate_backup

- name: Setup cron job
  template:
    src: cron-weblate-backup
    dest: /etc/cron.d/cron-weblate-backup
    owner: root
    group: root
    mode: 0644
  tags:
  - weblate_backup

- name: Create directory to mirror backups to
  file:
    dest: "{{ weblate_backup_topdir }}"
    mode: 0755
    state: directory
    owner: _backup_weblate
  tags:
  - weblate_backup
