Export in-memory inventory to yml or ini file

17 views
Skip to first unread message

Mike V

unread,
Jan 22, 2020, 7:11:10 PM1/22/20
to ansible...@googlegroups.com
I have a playbook that generates in-memory inventory.  The hosts are part of multiple groups.  Is there a module or easy way to export the in-memory inventory to an output file?

Vladimir Botka

unread,
Jan 22, 2020, 7:21:02 PM1/22/20
to Mike V, ansible...@googlegroups.com
Yes. It is. For example use this template

{% for group in groups %}
[{{ group }}]
{% for host in groups[group] %}
{{ host }}
{% endfor %}

{% endfor %}

HTH,

-vlado

Mike V

unread,
Jan 22, 2020, 7:36:13 PM1/22/20
to Vladimir Botka, ansible...@googlegroups.com
Works great!  I never used templates, just a little bit more help, how do I export the host variables and group variables too?
Thank you!

Mike V

unread,
Jan 22, 2020, 9:54:45 PM1/22/20
to Vladimir Botka, ansible...@googlegroups.com
I played around some more and was able to figure it out. thanks for teaching me how to fish.
Reply all
Reply to author
Forward
0 new messages