Breaking it down a bit

reboot_hint

is the name of the variable you have chosen to store the registered output 
in.

Inside reboot_hint is the output from the module.  The module results are 
put into a key value structure with a key of results.  This is probably 
done to keep the structured module output separate from other things that 
might come out of the module (like stdout and stderr contents).  Within 
results there are more key-and-value pairs, and the one we are interested 
in is reboot_required.

So that gets us to

reboot_hint.results.reboot_required

For when: to be useful it need to receive the some kind of test result - 
something that is either true or false.  We are in luck here because 
reboot_required contains a value of false or true so when: can use that 
directly.  

To make a slightly silly example, if reboot_required returned a string like 
"next_wednesday" then you would have to write the when: like this

when: reboot_hint.results.reboot_required == "next_wednesday"

There's a lot more you can do with this.  Two things that are well worth 
understanding are the kinds of things you can put in module output - well 
worth a read of the JSON spec which is only 1 page and can be found here: 
www.json.org and the other is getting an idea of the things you can do with 
variables using filters in Ansible see 
http://docs.ansible.com/ansible/playbooks_filters.html for ansible's built 
in filters and here for the full list of stuff that jinja2 (which ansible 
uses) can do.  http://jinja.pocoo.org/docs/templates/#builtin-filters 

Hope this helps,

Jon

On Wednesday, September 30, 2015 at 8:49:10 PM UTC+1, Dimitri Yioulos wrote:
>
> Jon,
>
> Both of your suggestions work; thanks!
>
> For my edification, why do either work when "reboot_required": true, and 
> not "reboot_required": false, or why don't they simply resolve against 
> "reboot_required" (without true or false)?
>
> Dimitri
>
>
> On Wednesday, September 30, 2015 at 9:38:33 AM UTC-4, Dimitri Yioulos 
> wrote:
>>
>> Hello, all.
>>
>> With help from the list, I have windows updates working via the rewritten 
>> win_updates module found here 
>> <https://github.com/ansible/ansible-modules-extras/pull/854>.  I'm now 
>> looking for a way to creat a reboot hint based on the return output.  
>> Here's what that output partially looks like when I run the module (using 
>> -v):
>>
>> changed: [sawintest02] => {"changed": true, "failed_update_count": 0, 
>> "found_update_count": 23, "installed_update_count": 23, "reboot_required": 
>> true, "updates": {"04f04253-f803-43b8-8b37-6841c614dd9f": {"id": 
>> "04f04253-f803-43b8-8b37-6841c614dd9f", "installed": true, "kb": 
>> ["3084135"], "title": "Security Update for Windows Server 2012 R2 
>> (KB3084135)"}, ~
>>
>> How would I parse this output to create a hint so that a reboot will be 
>> done if "reboot_required": true, and nothing be done if "reboot_required": 
>> false,
>>
>> I'm a terrible programmer, so your help is greatly appreciated.
>>
>> Dimitri
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/354f07b0-f428-4ef2-b2d7-2d97dc4a16d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to