- hosts: pfservers
  name: upgrade EL OS to latest version
  become: True
  gather_facts: False
  tags: upgrade

  pre_tasks:
  - name: Gather min only
    ansible.builtin.setup:
      gather_subset:
        - "!all"

  tasks:
    - name: Install packages missing from EL images
      yum:
        name: 'dhcp-client'
        state: 'present'
        update_cache: yes
      when: ansible_os_family == 'RedHat'
      register: upgrade_el_os_register_pkg
      retries: 3
      delay: 1
      until: upgrade_el_os_register_pkg is successful

    - name: update to latest OS version (EL)
      yum:
        name: '*'
        state: latest
        update_cache: no
      register: upgrade_os_el_register
      when: ansible_os_family == 'RedHat'

    - name: reboot to have latest Linux kernel packages in place when installing PacketFence
      reboot:
      when: upgrade_os_el_register is changed
