I'm attempting to use Ansible ec2_group to modify or append EC2 Security
Group rules. I tried to populate variables in the playbook used for the
names and descriptions of their corresponding security groups with either
variables defined in var_files or using just a standard loop containing
simple lists of strings. However, neither way worked. I'd highly appreciate
it if someone can help out.
My playbook 1:
---
- name: Update all SGs
hosts: localhost
vars_files:
- vars/all.yml
tasks:
- name: add rules to SGs
local_action:
module: ec2_group
name: "{{ item.name }}"
description: "{{ item.desc }}"
with_items: "{{ security_groups }}"
vpc_id: "{{ lookup('env','AWS_VPC_ID') }}"
region: us-west-1
purge_rules: false
rules:
- proto: tcp
from_port: 22
to_port: 22
cidr_ip: "{{ item }}"
with_items:
- 192.168.1.5/32
- 192.168.2.8/32
- 192.168.3.7/32
vars/all.yml:
security_groups:
- { name: "SG group 1", desc: "my SG1" }
- { name: "SG group 2", desc: "my SG2" }
- { name: "SG group 3", desc: "my SG3" }
My playbook 2:
---
- name: Update all SGs
hosts: localhost
tasks:
- name: add rules to SGs
local_action:
module ec2_group
name: "{{ item.name }}"
description: "{{ item.desc }}"
with_items:
- { name: 'SG group 1', desc: 'my SG1' }
- { name: 'SG group 2', desc: 'my SG2' }
- { name: 'SG group 3', desc: 'my SG3' }
vpc_id: "{{ lookup('env','AWS_VPC_ID') }}"
region: us-west-1
purge_rules: false
rules:
- proto: tcp
from_port: 22
to_port: 22
cidr_ip: "{{ item }}"
with_items:
- 192.168.1.5/32
- 192.168.2.8/32
- 192.168.3.7/32
The output of running playbook 1:
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/ansible-files/myplaybook1.yml': line
11, column 12, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
module ec2_group
name: "{{ item.name }}"
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
The output of running playbook 2:
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/ansible-files/mytest4.yml': line 8,
column 14, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
module ec2_group
name: "{{ item.name }}"
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/1a92b1a5-89e7-4c8a-9de1-8a3bd2e24885%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.