Ansible 1.7
I am trying to use either with_items or with_nested (if including a list of ports as well) to traverse a list of cidr addresses and create sec group rules from that …
Basically, this is failing repeatedly … and I guess its down to confusion around the correct scope to apply the with_items keyword …
I have something like this …
`
- name: Create security group
ec2_group:
name: “some-name”
description: “some description”
vpc_id: “vpc-blahblah”
region: “eu-north-4”
rules: - proto: tcp
from_port: 443
to_port: 443
cidr_ip: “{{ item }}”
with_items: - addr1/32
- addr2/32
- etc/32
`
In the above scope of usage, ansible is not able to see the variable … it’s exactly the same below when the with_items is nested in-line with and the following also does not work …
`
- name: Create security group
ec2_group:
name: “some-name”
description: “some description”
vpc_id: “vpc-blahblah”
region: “eu-north-4”
rules: - proto: tcp
from_port: 443
to_port: 443
cidr_ip: “{{ item }}”
with_items: - addr1/32
- addr2/32
- etc/32
`
The only variant that works is when it’s aligned with the ec2group line (see immediately below) … but it does not iterate and create several security groups … it iteratively, replaces a single entry with the latest value in the loop …
`
- name: Create security group
ec2_group:
name: “some-name”
description: “some description”
vpc_id: “vpc-blahblah”
region: “eu-north-4”
rules: - proto: tcp
from_port: 443
to_port: 443
cidr_ip: “{{ item }}”
with_items: - addr1/32
- addr2/32
- etc/32
`
I have looked at the docs for both ec2group and with_items, and it’s not obvious how this is supposed to be used … I suspect I may be making some basic mistake/omission … Any suggestions? thanks in advance.