---

- name: install ELRepo key
  rpm_key:
    state: present
    key: '{{ elrepo_key_url }}'

- name: install elrepo repository
  yum:
    name: '{{elrepo_url}}'
    state: present

- name: upgrade kernel
  yum:
    name: "{{elrepo_kernel_package}}"
    state: present
    enablerepo: elrepo-kernel
  register: upgrade

- name: change default grub entry
  lineinfile:
    dest: '/etc/default/grub'
    regexp: '^GRUB_DEFAULT=.*'
    line: 'GRUB_DEFAULT=0'
  when: upgrade.changed
  register: grub_entry

- name: re-generate grub-config
  command: grub2-mkconfig -o /boot/grub2/grub.cfg
  when: upgrade.changed and grub_entry.changed

- include: reboot.yml
  when: upgrade.changed