Ive stopped doing 
debug: var=hostvars 
and do 
debug: var=hostvars[inventory_hostname] 
or
debug: var=hostvars[item]
with_items: play_hosts 

As you do not get all the vars outputted in when you do it the first way, 
but the second way I do.  I am completely guessing as I have not dug into 
the code to see, but I am suspecting that hostvars is coming from a cache 
that is not up to date, and when you access the specific element in 
hostvars that is coming from a cache that contains the latest.

Thanks!
Michael

On Monday, October 20, 2014 4:14:04 PM UTC-5, Michael DeHaan wrote:
>
> "I *think* that debug: var=hostvars should print all the variables in 
> scope (for each host)"
>
> It doesn't do this, but rather looks for variable names inside hostvars.
>
> You can think of the "hostvars" syntax as a way to reference variables for 
> other hosts.
>
> I guess whether it should work might be a technicality, but that's what it 
> was intended for.
>
>
> On Wed, Oct 15, 2014 at 4:31 PM, Ross Rosen <[email protected] 
> <javascript:>> wrote:
>
>> Per the documentation and this thread: 
>> https://groups.google.com/d/msg/ansible-project/rE8aVu4LNS0/sGKweGPvffoJ
>> I *think* that debug: var=hostvars should print all the variables in 
>> scope (for each host).  I'm not sure what var=vars is - non-host-specific 
>> variables?
>>
>> In either case, I'm getting extremely odd behavior that I can't figure 
>> out.  I'm sorry this is long, but it is hopefully easy to follow and I 
>> suspect is either a simple answer or there is a bug.
>>
>> (some stuff removed for brevity or security)
>>
>> Here is my command line: 
>>      ansible-playbook playbook.yml --inventory-file dynamic_inventory.sh 
>> --limit stage --user xxx --private-key xxx.pub -e IS_VAGRANT=False -C
>>     
>> Here is the result of my dynamic inventory for host 'stage'
>>     {
>>         "hosts": [
>>             "192.xxx.xxx.176"
>>         ],
>>         "vars": {
>>             "HOST_NAME": "stage.yyyyyyyyy.com",
>>             "SERVER_NAME": "stage.yyyyyyyyy.com"
>>         }
>>     }
>>
>> Now here are the key plays, and results, from my playbook
>>
>> - debug: var=vars
>> >> This looks pretty good (but note it doesn't show variables from my 
>> inventory)
>>
>>     PLAY [all] 
>> ********************************************************************
>>
>>     TASK: [baseUbuntu | debug var=vars] 
>> *******************************************
>>     ok: [192.xxx.xxx.176] => {
>>         "vars": {
>>             "DIFFTOOL": "git --no-pager diff",
>>             ... <DELETED - but *no* HOST_NAME> ...
>>             "IS_VAGRANT": "False",
>>             ... <DELETED - but *no* SERVER_NAME> ...
>>             "_original_file": 
>> "/Users/xxxxxx/tmp/thissite/ansible_config/roles/baseUbuntu/tasks/main.yml",
>>             "always_run": false,
>>             "changed_when": null,
>>             "delegate_to": null,
>>             ... <DELETED> ...
>>             "role_uuid": "160302ff-f06f-4a78-8204-f0fcc4a8c750"
>>         }
>>     }
>>
>>
>>
>> - debug: var=hostvars
>> >> This looks wrong to me. Shouldn't it either be a superset of vars and 
>> my inventory variables? 
>> (HOST_NAME and SERVER_NAME)
>>
>>     TASK: [baseUbuntu | debug var=hostvars] 
>> ***************************************
>>     ok: [192.xxx.xxx.176] => {
>>         "hostvars": {
>>             "192.xxx.xxx.176": {
>>                 "IS_VAGRANT": "False"
>>             }
>>         }
>>     }
>>
>>
>>
>> Hmmm... maybe I I'm not properly setting my inventory variables.
>> Nope! See 'HOST_NAME' is properly set. Why doesn't it show up in vars or 
>> hostvars?
>>
>> - debug: msg="HOST_NAME = *{{ HOST_NAME }}*"
>>     TASK: [baseUbuntu | debug msg="HOST_NAME = *{{ HOST_NAME }}*"] 
>> ****************
>>     ok: [192.xxx.xxx.176] => {
>>         "msg": "HOST_NAME = *stage.yyyyyyyyy.com*"
>>     }
>>
>>
>> And this one is even weirder. I use {{ HOST_NAME }} and in the "name" 
>> clause it doesn't 
>> render and in the hostname clause it does!
>>
>> - name: "Set hostname to {{ HOST_NAME }}"
>>     hostname: name="{{ HOST_NAME }}"
>>
>>     TASK: [baseUbuntu | debug msg="HOST_NAME = *{{ HOST_NAME }}*"] 
>> ****************
>>     ok: [192.xxx.xxx.176] => {
>>         "msg": "HOST_NAME = *stage.yyyyyyyyy.com*"
>>     }
>>
>>
>> I'm baffled - I'd appreciate any tips. Thank you!
>>
>> -- 
>> 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] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/474c431e-8108-4739-a31d-f1c0461d76c2%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/474c431e-8108-4739-a31d-f1c0461d76c2%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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/1211a0c9-715e-4178-a8de-83e0dd4680a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to