I am very new to Ansible. We are trying to automate windows montly patches. But our playbook keep on fail when there is a update which requires a reboot. How to handle intellegent system reboot only if it requires.
I have a very big doubt that once reboot is triggered the winrm connection will lost or it will wait for some seconds. If the connection is lost then we are planning to handle that with pause option but i need code logic it should pause the execution process only if rebooted is done.
The win_updates module will give a reboot_required: True return value when one is required. With that information you can register the task and then have a follow up win_reboot task when reboot_required: True. See below for how to accomplish this.
name: Install Windows Updates
win_updates:
register: updates
name: Reboot after installing updates
win_reboot:
when: updates.reboot_required
What you given is absolutely correct. But i was blocked with different condition. While patching some updates won’t move forward without restart. in that case if i restart the connection established with ansible server will lost. For that i am using pause module in ansible. Once that pause is condition is executed how to resume the patching?
You should be using the win_reboot module to handle updates. It reboots the server and waits for it to come back online so it should be seemless and won’t continue until it is ready for another task. Your playbook would look something like this
I am almost there. Your code is working absolutely fine. But need to handle below logic.
We can’t say how many updates will ask for reboot so having win_updates multiple times in playbook can’t work (we cannot hard code) → If we have the logic when ever reboot is triggered the control should go for win_updates.
With the above given code. Second round of updates should execute only if win_reboot is executed other wise it should skip.
Me too new just from my scenario I am suggesting to use a handler on play book level.
And then added a notify to handler on each task where I expect a reboot to be done.