---
# Set Timezone
- name: Set timezone variables
  ansible.builtin.copy:
    content: 'Europe/Paris'
    dest: /etc/timezone
    owner: root
    group: root
    mode: 0644
    backup: true
    force: false
  notify:
    - Update timezone

# Disable ipv6
- name: Checking GRUB cmdline
  ansible.builtin.shell: "grep 'GRUB_CMDLINE_LINUX_DEFAULT=.*ipv6.disable=1.*' /etc/default/grub"
  register: grub_cfg_grep
  changed_when: false
  failed_when: false

- name: Disable IPV6 on GRUB cmdline
  ansible.builtin.replace:
    path: '/etc/default/grub'
    regexp: '^GRUB_CMDLINE_LINUX_DEFAULT="((\w.?)*)"$'
    replace: 'GRUB_CMDLINE_LINUX_DEFAULT="\1 ipv6.disable=1"'
  when: '"ipv6.disable=1" not in grub_cfg_grep.stdout'

# Remove snap
- name: Stop service snap, if running
  ansible.builtin.systemd:
    name: snapd
    state: stopped
  register: unused_disable # on enregistre le retour de la commande pour déclencher l'arret que si le service existe
  failed_when: "unused_disable is failed and ('find' not in unused_disable.msg and 'found' not in unused_disable.msg)"

- name: Uninstall
  ansible.builtin.apt:
    pkg:
      - snapd
      - gnome-software-plugin-snap
    state: absent
    purge: true

- name: Delete snap directory
  ansible.builtin.file:
    path:
      - ~/snap/
      - /var/cache/snapd/
    state: absent

# Install LibreOffice
- name: Apt Install Prerequis
  ansible.builtin.apt:
    update_cache: true
    name:
      - libreoffice
      - net-tools
