---
- name: load vars
  include_vars: "{{ ansible_distribution }}_{{ ansible_distribution_major_version }}.yml"
  when: extra_packages is not defined

- name: "Clear yum cache"
  command: yum clean all
  become: true
  when: ansible_os_family == 'RedHat'

- name: "Clear yum pending transactions"
  command: yum-complete-transaction --cleanup-only
  become: true
  when: ansible_os_family == 'RedHat'
 
- name: "Install extra packages with the epel repo enabled"
  yum: "name={{ item }} exclude={{ excludes|join(',') }} update_cache=yes state=present enablerepo=epel"
  with_items: "{{ extra_packages }}"
  become: true
  become_user: root
  when: ansible_os_family == 'RedHat' 
  register: result

- name: "Install extra packages from epel only"
  yum: "name={{ item }}  update_cache=yes state=present enablerepo=epel" # exclude={{ excludes|join(',') }}
  with_items: "{{ extra_packages_epel }}"
  become: true
  become_user: root
  when: ansible_os_family == 'RedHat'

- name: "Show yum install output"
  debug: 
    msg: "{{ result.results }}"

- name: "Install extra packages"
  apt: "name={{ item }} update_cache=yes state=present"
  with_items: "{{ extra_packages }}"
  become: true
  become_user: root
  when: ansible_os_family == 'Debian'
