# Ansible Reboot Check

**URL:** <https://forum.ansible.com/t/ansible-reboot-check/28760>\
**Category:** Ansible Project\
**Created:** [October 10, 2018, 7:56pm UTC](https://forum.ansible.com/t/ansible-reboot-check/28760 "2018-10-10T19:56:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Bidwell](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Chris\_Bidwell](https://forum.ansible.com/u/Chris_Bidwell)\
**Post date:** [October 10, 2018, 7:56pm UTC](https://forum.ansible.com/t/ansible-reboot-check/28760/1 "2018-10-10T19:56:03Z")

</div>

Hey all,

take a look at this and lemme know where I’m hosed at. The errors are a bit misleading:

---

<div class="post-metadata">

**Author:** ![Scott\_Sturdivant](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@Scott\_Sturdivant](https://forum.ansible.com/u/Scott_Sturdivant)\
**Post date:** [October 10, 2018, 10:13pm UTC](https://forum.ansible.com/t/ansible-reboot-check/28760/2 "2018-10-10T22:13:32Z")

</div>

The ‘check if reboot is required’ tasks were both skipped, resulting in ‘reboot\_required’ not being defined.

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [October 10, 2018, 10:40pm UTC](https://forum.ansible.com/t/ansible-reboot-check/28760/3 "2018-10-10T22:40:38Z")

</div>

Yes. One simple cure would be to do an initial set\_fact to set reboot\_required to false, so that even if neither of the skipped tasks sets it, the variable is there to be checked.

A second simple cure would be to set it to false after the the other tests, conditional upon it not already being defined, so:

- set fact:  
reboot\_required: “{{ reboot\_required |default(false) }}”

or

- set\_fact:  
reboot\_required: false  
when: reboot\_required is undefined

BTW both of those are off the top of my head so probably syntactically wrong but you get the idea 🙂

A slightly less simple cure would be to check whether it is defined as part of the test of its value. much as you have done with stdout length. I think is be less obvious to the reader.

when: reboot\_required is defined and reboot\_required == false

… again, I probably have the syntax wrong.

All of this presupposes that instead of directly checking components of a structured return value, you turn your various tests into a simple boolean as a separate operation; then afterwards you can use a much more readable “when: reboot\_required”. So in the stanzas where you have a structured value and are looking for a string in it, you would call the structured value something else, and generate reboot\_required from it. Just a thought.

Regards, K.
