I’m using win_updates module to carry out windows patching and it works pretty good.
Sometime, updates have dependencies and multiple playbook execution required.
I was thinking, if possible, to loop the playbook until “found_update_count > 0” without the need of running ansible-playbook multiple time after each finish.
I can’t from the top of my head recall if the “block” feature supports loops, but if it does I guess that’s the best way to do this.
As far as I can remember, Microsoft’s own config management tool for clients (SCCM) gets around this by simply doing 2 “passes” of patching. You could do that aswell, with some conditionals to only kick the second pass if it’s needed.
I’ve also read a post by Brian Coca which stated that “blocks do not support any type of loop”.
What other options can be used to re-run multiple tasks (one that checks/installs updates and the other reboots the server) until no updates available?
The solution Dag posted is what I’ve always done, and it works great for me. I’ve been advocating for block loop support (as a cleaner solution to exactly this issue) since before it shipped, but I don’t have the bandwidth to implement myself right now, and around here it’s kinda “put up or shut up”. If it doesn’t work for you, let us know why and maybe we can get it figured out.
I really wouldn’t recommend the “run the playbook in a loop” thing- you lose a lot of output fidelity and error handling, and it’s really just a way more expensive way to do what Dag suggested.
I actually originally wrote win_updates with a wrapper action that would handle the reboots automatically, but for various reasons (that I can’t recall) decided to abandon the wrapper before I shipped it…
“When you call include, Ansible actually places tasks from included file into the execution queue after the current task.” (http://stackoverflow.com/a/38481496)
The example below is a hack but it has a useful property whereby tasks in the inner taskbook will not be run if the play was ended. i.e.
calling inner-taskbook 1st time
running tasks
calling inner-taskbook 2nd time
running tasks
calling inner-taskbook 3rd time
running tasks
play ended because we’ve determined that we’ve finished the work
calling inner-taskbook 4th time
noop
calling inner-taskbook 5th time
noop
calling inner-taskbook nth time
noop
So if you configure the with_sequence parameters as you would have done the “until:” command’s “retries” attribute then you kinda simulate the retry functionality with the example below.
You will notice that the taskbook does get “included” 100 times but the tasks in it are ONLY executed the number of times actually required.
run.sh:
—snip—
#!/usr/bin/env bash
ansible-playbook -vvv -i ‘localhost,’ -c local main.yml
—snip—
Ack. I just noticed that the example below is not a good solution since it never did run the “Performing tasks after windows updates.” task in the main.yml file.