# Transform dictionary into lists for module consumption

**URL:** <https://forum.ansible.com/t/transform-dictionary-into-lists-for-module-consumption/23188>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [December 6, 2016, 7:36pm UTC](https://forum.ansible.com/t/transform-dictionary-into-lists-for-module-consumption/23188 "2016-12-06T19:36:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geoff\_Webster](https://avatars.discourse-cdn.com/v4/letter/g/f07891/32.png) [@Geoff\_Webster](https://forum.ansible.com/u/Geoff_Webster)\
**Post date:** [December 6, 2016, 7:36pm UTC](https://forum.ansible.com/t/transform-dictionary-into-lists-for-module-consumption/23188/1 "2016-12-06T19:36:23Z")

</div>

I am trying to simplify some variable files for our developers and I am wondering if I can do this transform with existing filter/lookup plugins Ansible.

I’ll have this dictionary (and the fields are not static, there could be more settings):

OptionSettings:  
aws:elasticbeanstalk:command:  
BatchSize: ‘30’  
BatchSizeType: Percentage  
aws:elasticbeanstalk:sns:topics:  
Notification Endpoint: [me@example.com](mailto:me@example.com)

And I want to transform the elements under OptionSettings to match what the module/API is expecting:

OptionSettingsTransform:

- Namespace: aws:elasticbeanstalk:command  
OptionName: Batch Size  
Value: “30”
- Namepsace: aws:elasticbeanstalk:command  
OptionName: BatchSizeType  
Value: Percentage
- Namespace: aws:elasticbeanstalk:sns:topics  
OptionName: Notification Endpoint  
Value: [me@example.com](mailto:me@example.com)

So it involves iterating over each subelement of OptionSettings and then each subelement of each namespace while retaining the namespace it is working within. I have tried looking at with\_items, together, subelements, but I can’t seem to wrap my head around it. Any ideas? Is this too much and would I need to implement a custom lookup plugin in python to do this?

Any help/suggestions would be appreciated 🙂

---

<div class="post-metadata">

**Author:** ![viper233](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/viper233/32/2060_2.png) [@viper233](https://forum.ansible.com/u/viper233)\
**Post date:** [December 8, 2016, 5:33am UTC](https://forum.ansible.com/t/transform-dictionary-into-lists-for-module-consumption/23188/2 "2016-12-08T05:33:35Z")

</div>

Use the jinja map attribute function to extract the items into a list.

I’ve put together an example here  
[http://docs.ansible.com/ansible/ec2\_vpc\_subnet\_facts\_module.html](http://docs.ansible.com/ansible/ec2_vpc_subnet_facts_module.html)

There is some more documentation here with links here  
[http://docs.ansible.com/ansible/playbooks\_filters.html](http://docs.ansible.com/ansible/playbooks_filters.html)

Sorry I don’t have the time to go through a full example with your use case, hope this helps.
