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 %}
Written by Darryl Stoflet
Related protips
1 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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ansible
Authors
Misha Behersky
78.97K
tartansandal
73.31K
Related Tags
#ansible
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#