# ec2\_group failed to template

**URL:** <https://forum.ansible.com/t/ec2-group-failed-to-template/19964>\
**Category:** Ansible Project\
**Created:** [December 8, 2015, 4:06pm UTC](https://forum.ansible.com/t/ec2-group-failed-to-template/19964 "2015-12-08T16:06:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edgardo\_Vega](https://avatars.discourse-cdn.com/v4/letter/e/b2d939/32.png) [@Edgardo\_Vega](https://forum.ansible.com/u/Edgardo_Vega)\
**Post date:** [December 8, 2015, 4:06pm UTC](https://forum.ansible.com/t/ec2-group-failed-to-template/19964/1 "2015-12-08T16:06:27Z")

</div>

I am having a strange issue

I have a role that looks like the following

# roles/ec2\_sg/tasks/main

- name: Create Security Group  
ec2\_group:  
profile: “{{ profile }}”  
name: “{{ type }}”  
description: “ports required to communicate to {{ type }}”  
vpc\_id: “{{ aws\_vpc\_id }}”  
region: “{{ aws\_region }}”  
rules: “{{ sg\_rules }}”

When I have the following playbook it fails with the following error

- hosts: localhost  
connection: local  
gather\_facts: false  
vars\_files:

- group\_vars/{{ env }}  
tags:

- test  
roles:

- role: ec2\_sg  
type: “test”  
sg\_rules:

- proto: tcp  
from\_port: 8081  
to\_port: 8082  
cidr\_ip: “{{ public\_cidr }}”

TASK: [ec2\_sg | Create Security Group] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [localhost] =\> Failed to template {% if [{‘to\_port’: 8082, ‘from\_port’: 8081, ‘cidr\_ip’: u’0.0.0.0/0’, ‘proto’: ‘tcp’}] %} True {% else %} False {% endif %}: template error while templating string: expected token ‘,’, got ‘string’

FATAL: all hosts have already failed – aborting

but if I do it works.

- hosts: localhost  
connection: local  
gather\_facts: false  
vars\_files:
- group\_vars/{{ env }}  
vars:  
type: “test”  
sg\_rules:
- proto: tcp  
from\_port: 8081  
to\_port: 8082  
cidr\_ip: “{{ public\_cidr }}”  
tags:
- test  
roles:
- role: ec2\_sg  
type: “test”

It really makes no sense. Does anyone have any idea what is happening?

Appreciate the help in advance.

Cheers,

Edgardo
