Export in-memory inventory to yml or ini file

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?

Yes. It is. For example use this template

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

HTH,

  -vlado

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!

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