# Using a list variable to generate a list of dicts for another variable setting

**URL:** <https://forum.ansible.com/t/using-a-list-variable-to-generate-a-list-of-dicts-for-another-variable-setting/16971>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [December 5, 2014, 3:35pm UTC](https://forum.ansible.com/t/using-a-list-variable-to-generate-a-list-of-dicts-for-another-variable-setting/16971 "2014-12-05T15:35:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bret\_Martin](https://avatars.discourse-cdn.com/v4/letter/b/47e85d/32.png) [@Bret\_Martin](https://forum.ansible.com/u/Bret_Martin)\
**Post date:** [December 5, 2014, 3:35pm UTC](https://forum.ansible.com/t/using-a-list-variable-to-generate-a-list-of-dicts-for-another-variable-setting/16971/1 "2014-12-05T15:35:10Z")

</div>

I’d like to have a list of networks in a variable in group\_vars/all, something like

internal-networks:

- 10.2.3.0/24
- 10.3.4.0/24

and ideally reference it in a later variable setting, say in host\_vars/aws-vpc-foo:

security\_groups:  
default:  
rules:

- { proto: all, group\_name: default }
- { proto: all, cidr\_ip: 10.2.3.0/24 }
- { proto: all, cidr\_ip: 10.3.4.0/24 }

I’d like to generate those last two elements from internal-networks, but I’m struggling with how to do this. security\_groups[‘default’][‘rules’] is later passed to the ec2\_group module in a playbook, like

- name: configure security groups  
local\_action:  
module: ec2\_group  
…  
rules: ‘{{ item.value.rules | default(None) }}’  
with\_dict: ‘{{ security\_groups | default({}) }}’

I’m trying to not have to repeat the list of internal networks in many places. (It’s longer than the two elements in my example.) Does anyone have any suggestions?

Thanks!

–Bret
