---
- name: GJK client setup
  hosts: all
  user: root

  tasks:
    # Repositories
    - name: Import RPM Fusion (free) key
      ansible.builtin.rpm_key:
        state: present
        key: https://rpmfusion.org/keys?action=AttachFile&do=get&target=RPM-GPG-KEY-rpmfusion-free-fedora-2020

    - name: Import RPM Fusion (non-free) key
      ansible.builtin.rpm_key:
        state: present
        key: https://rpmfusion.org/keys?action=AttachFile&do=get&target=RPM-GPG-KEY-rpmfusion-nonfree-fedora-2020

    - name: Import Microsoft VS Code key
      ansible.builtin.rpm_key:
        state: present
        key: https://packages.microsoft.com/keys/microsoft.asc

    - name: Activate RPM Fusion repository
      dnf:
        name:
          - https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-{{ ansible_distribution_major_version }}.noarch.rpm
          - https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-{{ ansible_distribution_major_version }}.noarch.rpm
        state: present

    - name: Activate VS Code repository
      copy:
        src: files/repositories/vscode
        dest: /etc/yum.repos.d/vscode.repo


    # Flatpak
    - name: Enable flathub repo
      command: "{{ item }}"
      loop: "{{ commands }}"
      vars:
        commands:
          - "flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo"
          - "flatpak remote-modify --enable flathub"


    - name: Upgrade packages
      dnf:
        update_cache: true
        name: "*"
        state: latest

    - name: Install NVIDIA drivers
      dnf:
        name:
          - akmod-nvidia
        state: present
      when: inventory_hostname in groups['pov:children']

    - name: Set default boot option to Windows
      command: "grub2-set-default \"{{ default_boot_option }}\""
      vars:
        default_boot_option: >-
          {% if inventory_hostname in groups['pov:children'] %}
            Windows 8 (on /dev/sda1)
          {% elif inventory_hostname in groups['pom:children'] %}
            Windows Boot Manager (on /dev/nvme0n1p1)
          {% endif %}
      when:
        - inventory_hostname in groups['pov:children']
        - inventory_hostname in groups['pom:children']

    - name: Add Czech keyboard layout
      command: "localectl set-x11-keymap us,cz"

    # Firefox
    - name: Ensure Firefox addons folder exists
      file:
        path: /usr/lib64/firefox/distribution/extensions
        state: directory
    - name: Install firefox addons
      copy:
        src: "{{ item }}"
        dest: "/usr/lib64/firefox/distribution/extensions/"
      loop:
        - "files/firefox-addons/uBlock0@raymondhill.net.xpi"

    - name: Setup user student
      user:
        name: student
        password: $6$7Z.h8Q6CO9AevdIp$8W2nuvD7ZqeXBO.Azsayx2tJ4L0KD44hOz5aNzpGPN/hUtaROvmY7aJ0x7Ie3CPawp6lV4ln2fHQQ7V5Yuy7k0
        groups:
          - dialout  # Arduino serial access
        state: present
        # state: absent
        # remove: true
