# Generating Lists & Dictionaries on the fly? Is it possible?

**URL:** <https://forum.ansible.com/t/generating-lists-dictionaries-on-the-fly-is-it-possible/13637>\
**Category:** Ansible Project\
**Created:** [October 9, 2013, 9:25am UTC](https://forum.ansible.com/t/generating-lists-dictionaries-on-the-fly-is-it-possible/13637 "2013-10-09T09:25:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan7](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@Dan7](https://forum.ansible.com/u/Dan7)\
**Post date:** [October 9, 2013, 9:25am UTC](https://forum.ansible.com/t/generating-lists-dictionaries-on-the-fly-is-it-possible/13637/1 "2013-10-09T09:25:52Z")

</div>

Hey,

I’m interested in generating variables/facts on the fly. I want to gather those facts from the server and put them into an iteratable list of dictionaries.

Is it possible?

I know about register. But I don’t know how to create dicts by using it.

Is there a filter that can get a JAML/JSON input and convert it into an ansible friendly data structure?

Any ideas of how should I approach this?

Thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 9, 2013, 1:05pm UTC](https://forum.ansible.com/t/generating-lists-dictionaries-on-the-fly-is-it-possible/13637/2 "2013-10-09T13:05:23Z")

</div>

I’d like to understand more about the use case first, before making suggestions about what you should do.

Can you walk me through what the end user scenario of things you are doing is (i.e. the why, not the how)?

---

<div class="post-metadata">

**Author:** ![Dan7](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@Dan7](https://forum.ansible.com/u/Dan7)\
**Post date:** [October 9, 2013, 1:39pm UTC](https://forum.ansible.com/t/generating-lists-dictionaries-on-the-fly-is-it-possible/13637/3 "2013-10-09T13:39:49Z")

</div>

Hey,

I want to fetch some internal data that was generated by some of our apps. The data can be stored in files.

Thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 9, 2013, 1:52pm UTC](https://forum.ansible.com/t/generating-lists-dictionaries-on-the-fly-is-it-possible/13637/4 "2013-10-09T13:52:43Z")

</div>

What do you want to do with that data?

What format is that data in, etc?

---

<div class="post-metadata">

**Author:** ![Dan7](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@Dan7](https://forum.ansible.com/u/Dan7)\
**Post date:** [October 9, 2013, 2:17pm UTC](https://forum.ansible.com/t/generating-lists-dictionaries-on-the-fly-is-it-possible/13637/5 "2013-10-09T14:17:02Z")

</div>

Hey again,

I want to allocate resources dynamically on the php-fpm pools.

I can provide the data in whatever way needed. The app that provides the data was coded inhouse, so I basically can do whatever format that is needed.

Thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 9, 2013, 2:21pm UTC](https://forum.ansible.com/t/generating-lists-dictionaries-on-the-fly-is-it-possible/13637/6 "2013-10-09T14:21:53Z")

</div>

If you want to absorb some data about the remote system into your application, I would look into writing a custom fact module.

See the “module development” page for details.

---

<div class="post-metadata">

**Author:** ![Dan7](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@Dan7](https://forum.ansible.com/u/Dan7)\
**Post date:** [October 9, 2013, 2:47pm UTC](https://forum.ansible.com/t/generating-lists-dictionaries-on-the-fly-is-it-possible/13637/7 "2013-10-09T14:47:37Z")

</div>

Thanks for the answer. I’ll check it out.

Regarding generating lists & dictionaries on the fly. Maybe merging dicts/lists? Is it possible?

Thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 9, 2013, 3:07pm UTC](https://forum.ansible.com/t/generating-lists-dictionaries-on-the-fly-is-it-possible/13637/8 "2013-10-09T15:07:08Z")

</div>

There’s some ability to merge variables in inventory together via the merge\_behavior setting in ansible.cfg, but it’s limited.
