# reboot host based on ansible output

**URL:** <https://forum.ansible.com/t/reboot-host-based-on-ansible-output/38114>\
**Category:** Ansible Project\
**Created:** [June 16, 2023, 1:47pm UTC](https://forum.ansible.com/t/reboot-host-based-on-ansible-output/38114 "2023-06-16T13:47:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [June 16, 2023, 1:47pm UTC](https://forum.ansible.com/t/reboot-host-based-on-ansible-output/38114/1 "2023-06-16T13:47:10Z")

</div>

I got pb that based on output will say:

reboot required: True  
or reboot required: False

if its false how do i skip the reboot on the following task?

---

<div class="post-metadata">

**Author:** ![Will\_McDonald](https://avatars.discourse-cdn.com/v4/letter/w/f475e1/32.png) [@Will\_McDonald](https://forum.ansible.com/u/Will_McDonald)\
**Post date:** [June 16, 2023, 2:07pm UTC](https://forum.ansible.com/t/reboot-host-based-on-ansible-output/38114/2 "2023-06-16T14:07:15Z")

</div>

You probably need a handler with a changed\_when condition.

[https://docs.ansible.com/ansible/latest/playbook\_guide/playbooks\_handlers.html#handlers](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_handlers.html#handlers)  
[https://docs.ansible.com/ansible/latest/playbook\_guide/playbooks\_error\_handling.html#defining-changed](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html#defining-changed)

See this discussion:

[https://unix.stackexchange.com/a/707238](https://unix.stackexchange.com/a/707238)

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [June 16, 2023, 5:51pm UTC](https://forum.ansible.com/t/reboot-host-based-on-ansible-output/38114/3 "2023-06-16T17:51:53Z")

</div>

can i do something like this instead. using when condition

- name: Run Esxcli command

vmware\_host\_esxcli:

hostname: ‘{{ vcenter\_hostname }}’

username: ‘{{ admin}}’

password: ‘{{ pass }}’

esxi\_hostname: “{{ inventory\_hostname }}”

validate\_certs: no

cmd: ‘{{ cmd }}’

delegate\_to: localhost

register: esxcli\_output

- name: Display esxcli output

debug:

var: esxcli\_output.stdout\_lines

- name: Reboot ESXi host

vmware\_host\_powerstate:

hostname: ‘{{ vcenter\_hostname }}’

username: ‘{{ admin}}’

password: ‘{{ pass }}’

esxi\_hostname: “{{ inventory\_hostname }}”

validate\_certs: no

state: reboot-host

delegate\_to: localhost

**when: “esxcli\_output.stdout\_lines[0] != ‘Reboot Required: false’”**
