Hello,
For some reason, when my group_vars list only has 1 item under "test2:" it
get the following error. If I have more than 1 list item under "test2:"
then everything works correctly. Is this an Ansible bug or do I need to do
something differently?
{'msg': 'AnsibleUndefinedVariable: One or more undefined variables: list
object has no element 1', 'failed': True}
group vars:
-----------------
---
VPCRegions:
test1:
- vpc1
- vpc2
test2:
- vpc1
template:
--------------
{
"Resources" : {
{% set list_length = item.values()|length %}
{% for index in range(list_length) %}
"TomcatManager{{ item.value[index]|replace("-", "") }}" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "8080",
"VpcId" : "{{ item.value[index] }}",
"SecurityGroupIngress" : [
{
"IpProtocol" : "tcp",
"FromPort" : "8080",
"ToPort" : "8080",
"CidrIp" : "0.0.0.0/0"
}
],
"SecurityGroupEgress" : [
{
"IpProtocol" : "tcp",
"FromPort" : "8080",
"ToPort" : "8080",
"CidrIp" : "0.0.0.0/0"
}
]
}
},
{% endfor %}
{% set list_length = item.values()|length %}
{% for index in range(list_length) %}
"SSH{{ item.value[index]|replace("-", "") }}" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "22",
"VpcId" : "{{ item.value[index] }}",
"SecurityGroupIngress" : [
{% for ip in ips %}
{
"IpProtocol" : "tcp",
"FromPort" : "22",
"ToPort" : "22",
"CidrIp" : "{{ ip }}/32"
}
{% if not loop.last %}
,
{% endif %}
{% endfor %}
]
}
}
{% if not loop.last %}
,
{% endif %}
{% endfor %}
}
}
main.yml task
---------------------
---
# Generate Cloudformation securitygroup templates for each region
- name: create cloudformation json templates for each region
tags:
- cloudformation-templates
local_action:
module: template src=tomcat-ssh-securitygroups.j2
dest=/tmp/tomcat-ssh-securitygroups-{{ item.key }}.json
with_dict: VPCRegions
# run each template for each region in AWS
- name: create webservers & ssh security groups in based on template for
all vpcs in region list
with_dict: VPCRegions
cloudformation:
stack_name: "chanaka-cloudformation"
state: "present"
region: "{{ item.key }}"
disable_rollback: true
template: "/tmp/tomcat-ssh-securitygroups-{{ item.key }}.json"
--
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/82ab7d31-c6e8-4e6c-b1dd-17d6723449cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.