# Export in-memory inventory to yml or ini file

**URL:** <https://forum.ansible.com/t/export-in-memory-inventory-to-yml-or-ini-file/32034>\
**Category:** Ansible Project\
**Created:** [January 23, 2020, 12:10am UTC](https://forum.ansible.com/t/export-in-memory-inventory-to-yml-or-ini-file/32034 "2020-01-23T00:10:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_V](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mike\_V](https://forum.ansible.com/u/Mike_V)\
**Post date:** [January 23, 2020, 12:10am UTC](https://forum.ansible.com/t/export-in-memory-inventory-to-yml-or-ini-file/32034/1 "2020-01-23T00:10:42Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [January 23, 2020, 12:20am UTC](https://forum.ansible.com/t/export-in-memory-inventory-to-yml-or-ini-file/32034/2 "2020-01-23T00:20:48Z")

</div>

Yes. It is. For example use this template

&nbsp;&nbsp;{% for group in groups %}  
&nbsp;&nbsp;[{{ group }}]  
&nbsp;&nbsp;{% for host in groups[group] %}  
&nbsp;&nbsp;{{ host }}  
&nbsp;&nbsp;{% endfor %}  
&nbsp;&nbsp;  
&nbsp;&nbsp;{% endfor %}

HTH,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![Mike\_V](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mike\_V](https://forum.ansible.com/u/Mike_V)\
**Post date:** [January 23, 2020, 12:35am UTC](https://forum.ansible.com/t/export-in-memory-inventory-to-yml-or-ini-file/32034/3 "2020-01-23T00:35:47Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Mike\_V](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mike\_V](https://forum.ansible.com/u/Mike_V)\
**Post date:** [January 23, 2020, 2:54am UTC](https://forum.ansible.com/t/export-in-memory-inventory-to-yml-or-ini-file/32034/4 "2020-01-23T02:54:19Z")

</div>

I played around some more and was able to figure it out. thanks for teaching me how to fish.
