# building up dynamic structure

**URL:** <https://forum.ansible.com/t/building-up-dynamic-structure/14701>\
**Category:** Ansible Project\
**Created:** [March 4, 2014, 9:13pm UTC](https://forum.ansible.com/t/building-up-dynamic-structure/14701 "2014-03-04T21:13:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Birdsong](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@David\_Birdsong](https://forum.ansible.com/u/David_Birdsong)\
**Post date:** [March 4, 2014, 9:13pm UTC](https://forum.ansible.com/t/building-up-dynamic-structure/14701/1 "2014-03-04T21:13:58Z")

</div>

I’m trying to figure out how to emit a configuration file for jmxtrans. The config is json, the values I need to fill in are known by ansible, but I’m having a hell of a time building up the dict structure and dumping to json using the template module’s to\_json filter.

The simple explanation is that I’d like to loop over a list of servers from an inventory group, copy a few dictionaries from a vars file thereby building up a completely new dict and then dump that to a json file that jmxtrans uses for configuration.

If I had a way to turn on extension, I could do all of this in jinja2:  
[https://gist.github.com/davidbirdsong/9355702](https://gist.github.com/davidbirdsong/9355702)

I keep needing to be able to turn on extensions and take that as an indicator that I’m doing it the wrong way. Perhaps I am? Is there a more ansible-native way to loop on data and create new structures at play-time?

Here’s my vars.yml file: [https://gist.github.com/davidbirdsong/9355770](https://gist.github.com/davidbirdsong/9355770)
