- name: Add repository
  ansible.builtin.yum_repository:
    name: "{{ item.name }}"
    description: "Ansible repositories"
    baseurl: "{{ item.baseurl }}"
    async: yes
    gpgkey: "{{ item.gpgkey }}"
  with_items:  "{{ required_repository }}"  
  when: required_repository is defined   

- name: Update packages
  yum: 
    name: '*'
    state: latest
    update_cache: yes
    update_only: yes
  retries: 3
  delay: 10  

- name: Remove packates not needed anymore
  yum:
    autoremove: yes   
  retries: 3
  delay: 10

- name: Install required packages
  yum: 
    state: latest 
    update_cache: yes
    pkg: "{{ item }}"
  with_items:  "{{ required_packages }}" 
  retries: 3
  delay: 10    
  when: required_packages is defined

- name: configure flatpak
  community.general.flatpak_remote:
    name: flathub
    state: present
    flatpakrepo_url: https://dl.flathub.org/repo/flathub.flatpakrepo

- name: update flatpaks
  shell:
    cmd: flatpak update --noninteractive    

- name: install flatpak
  become_user: user
  community.general.flatpak:
    name: "{{ item }}"
  with_items:  "{{ required_flatpak_packages }}"     
  when: required_flatpak_packages is defined

- name: Manual install packages
  ansible.builtin.yum:
    name: "{{ item.url }}"
    state: present
    disable_gpg_check: yes
  with_items:  "{{ required_manual_packages }}"    
  when: required_manual_packages is defined

- name: set gui
  shell:
    cmd: systemctl set-default graphical.target 

- name: ensure fonts directory
  become_user: user
  file:
    path: "{{ lookup('env', 'HOME') }}/.fonts"
    state: directory

- name: FiraCode exists
  become_user: user
  shell: "ls {{ lookup('env', 'HOME') }}/.fonts/*FiraCode*"
  register: FiraCode_exists
  ignore_errors: yes

- name: Download FiraCode
  when: FiraCode_exists is failed
  become_user: user
  ansible.builtin.unarchive:
    src: https://github.com/ryanoasis/nerd-fonts/releases/download/v2.2.2/FiraCode.zip
    dest: "{{ lookup('env', 'HOME') }}/.fonts/"
    remote_src: yes