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

12 views
Skip to first unread message

Bret Martin

unread,
Dec 5, 2014, 10:35:10 AM12/5/14
to ansible...@googlegroups.com
I'd like to have a list of networks in a variable in group_vars/all, something like

internal-networks:

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
Reply all
Reply to author
Forward
0 new messages