---

- name: update grub
  command: update-grub
  failed_when: ('error' in update_grub_result.stderr)
  register: update_grub_result
  become: yes
  notify: warn reboot

# Tell the user that they should reboot the host
# Having Ansible reboot the host can get tricky and may be surprising to the user
#
# Originally tried doing this the 'debug' module and setting 'changed_when: True'
# so that the message would appear in yellow, but 'debug' is hardcoded to always
# show in green which is too easy to miss.
# https://github.com/ansible/ansible/issues/14430
- name: warn reboot
  fail:
    msg: "WARNING: {{ inventory_hostname }} has an updated grub config and must be rebooted manually"
  ignore_errors: true
