---
- name: Set a hostname
  ansible.builtin.hostname:
    name: "camino-{{ env }}"
  become: True
- name: Set timezone to Europe/Paris
  community.general.timezone:
    name: Europe/Paris
  become: True
- name: Upgrade machine
  ansible.builtin.apt:
    upgrade: safe
    update_cache: yes
  become: True
- name: Install rsync
  ansible.builtin.apt:
    name: rsync
    state: present
  become: True
- name: Install cron
  ansible.builtin.apt:
    name: cron
    state: present
  become: True
- name: Configure la machine pour installer docker
  block:
    - name: Install tools for apt
      ansible.builtin.apt:
        name:
          - ca-certificates
          - curl
          - gnupg
        state: present
      become: True
    - name: Ajoute les clés de signature pour docker
      ansible.builtin.apt_key:
        url: "https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg"
        keyring: /etc/apt/trusted.gpg.d/docker.gpg
        state: present
      become: True
    - name: Ajoute le repository pour pouvoir installer docker
      ansible.builtin.apt_repository:
        repo: "deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/docker.gpg] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable"
        state: present
        update_cache: True
        filename: docker
      become: True
    - name: Install docker
      ansible.builtin.apt:
        name: docker-ce
        state: latest
      become: True
    - name: Install docker client
      ansible.builtin.apt:
        name: docker-ce-cli
        state: latest
      become: True
- name: Ajoute les variables liées au bon environnement
  ansible.builtin.include_vars:
    file: "{{ env }}.yml"
- name: Ajoute les variables chiffrées liées au bon environnement
  ansible.builtin.include_vars:
    file: "{{ env }}_crypt.yml"
- name: Restic
  block:
    - name: Install restic
      ansible.builtin.apt:
        name: restic
        state: latest
      become: True
    - name: Ajoute les variables d'environnement
      ansible.builtin.template:
        src: restic_data
        dest: /srv/scripts/
        mode: u=rwx,g=rx,o=r
        owner: camino
        group: users
      become: True
- name: journalctl
  block:
    - name: Limite la taille maximum des fichiers de logs à 1GB
      ansible.builtin.lineinfile:
        path: /etc/systemd/journald.conf
        regexp: '^SystemMaxUse='
        line: SystemMaxUse=1G
      become: True
      register: limit_journal_size
    - name: Redémarre systemd-journald
      ansible.builtin.systemd_service:
        state: restarted
        name: systemd-journald
      when: limit_journal_size.changed
      become: True
