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

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