I have got a playbook where i need to check if the host fact for reboot is set to true, i need to execute the rest of the instructions for that particular host in the inventory only if the reboot condition is true.
Following is the playbook. I would like to avoid executing all the tasks for the host where the condition ansible_facts[‘Pending_Reboot’] == false or when: ansible_facts[‘Pending_Reboot’] != false. In such case, the execution should be skipped for that particular host and move to next host in the inventory.
`
-
hosts: all
gather_facts: false
tasks: -
name: Check and Reboot Server based on Pending_Reboot Fact
shell: “sleep 5 && reboot”
async: 1
poll: 0
when: ansible_facts[‘Pending_Reboot’] == true -
name: Pause for 10 seconds
pause:
seconds: 10 -
name: Wait for Re-connection
wait_for_connection:
connect_timeout: 5
sleep: 5
delay: 90
timeout: 600 -
name: Run checkLinuxSystemUpdateStatusTask task file to re-validate Reboot Status
include: checkLinuxSystemUpdateStatusTask.yml
`
What is the best and least time consuming way of doing this? I was checking the documentation for block but i am not sure if i can use the conditions for a block.
Thanks in Advance.
Regards,
Ankit