Last Updated: July 27, 2016
·
2.654K
· dstoflet

Dump hostvars

Ansible is able to do pretty complex orchestration and wire multiple components together. Generally to do that you need to know whats in the hostvars for each host ref'd in a playbook and then use jinja templates to generate the conf with the 'wiring'.
I use a simple playbook to generate a dump of all the hostvars each host can see to better understand what variables are available to 'wire' hosts together as well ensure the hosts are accessible to my playbook

checkvars.yml (playbook)

tasks:
  - name: Generate a /tmp/ansible.vars to check for hostvars
     action: template src=templates/checkvars.j2 dest=/tmp/ansible.vars

Then in checkvars.j2

{% for k,v in hostvars.iteritems() %}
Key {{k}} Value: {{v|pprint}}
{% endfor %}

1 Response
Add your response

It's totally useful to know how to iterate over them, though here are some other neat tricks:

{{ hostvars | to_json }}

{{ hostvars | to yaml }}
over 1 year ago ·