---
- name: Ajoute le script de backup
  ansible.builtin.template:
    src: backup
    dest: /srv/scripts/
    mode: u=rwx,g=rx,o=r
    owner: camino
    group: users
  become: True
- name: Ajoute le job de backup de la prod
  ansible.builtin.cron:
    name: "backup"
    minute: "0"
    hour: "2"
    job: "/srv/scripts/backup"
    user: camino
  become: True
- name: Configure le S3 pour les backups
  block:
    - name: Install s3cmd
      ansible.builtin.apt:
        name: s3cmd
        state: present
      become: True
    - name: Ajoute le fichier owner
      ansible.builtin.template:
        src: owner.cfg
        dest: /srv/scripts/
        mode: u=rwx,g=rx,o=r
        owner: camino
        group: users
      become: True
      register: owner
    - name: Ajoute le fichier bucket-ro
      ansible.builtin.template:
        src: bucket-ro.json
        dest: /srv/scripts/
        mode: u=rwx,g=rx,o=r
        owner: camino
        group: users
      become: True
      register: bucket_ro
    - name: Applique les policies sur le bucket s3
      shell: 's3cmd -c /srv/scripts/owner.cfg setpolicy /srv/scripts/bucket-ro.json s3://Camino'
      when: bucket_ro.changed or owner.changed