# Incorrect use of with\_indexed\_items?

**URL:** <https://forum.ansible.com/t/incorrect-use-of-with-indexed-items/19651>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [October 29, 2015, 2:50pm UTC](https://forum.ansible.com/t/incorrect-use-of-with-indexed-items/19651 "2015-10-29T14:50:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rob\_Wilkerson](https://avatars.discourse-cdn.com/v4/letter/r/c67d28/32.png) [@Rob\_Wilkerson](https://forum.ansible.com/u/Rob_Wilkerson)\
**Post date:** [October 29, 2015, 2:50pm UTC](https://forum.ansible.com/t/incorrect-use-of-with-indexed-items/19651/1 "2015-10-29T14:50:04Z")

</div>

I’m working on a playbook that will:

1. Launch n EC2 instances
2. Tag each with a “meaningful” name

The name should look something like -\<%02d\> (e.g. dev-ws03 or prd-db01).

Step 1 works great, but applying the Name tag is failing and I can’t see my mistake:

- name: Instances | Tag each new instance with a name  
ec2\_tag:  
aws\_access\_key: “{{ awscli.access\_key }}”  
aws\_secret\_key: “{{ awscli.secret\_key }}”  
region: “{{ aws.region }}”  
resource: “{{ item }}”  
state: present  
tags:  
Name: “{{ env\_short }}-{{ ‘ws%02d’ | format(item.0) }}”  
with\_indexed\_items: webservers.instance\_ids

Note that the {{ webservers }} variable is registered by the ec2 module after the launch task completes. To my inexperienced eye, it looks like {{ item.0 }} contains the value rather than the index. Here’s the error:

failed: [localhost] =\> (item=(0, ‘i-8e0aaf32’)) =\> {“failed”: true, “item”: [0, “i-8e0aaf32”], “parsed”: false}  
Traceback (most recent call last):  
File “/Users/robwilkerson/.ansible/tmp/ansible-tmp-1446129334.17-9751906117513/ec2\_tag”, line 1958, in   
main()  
File “/Users/robwilkerson/.ansible/tmp/ansible-tmp-1446129334.17-9751906117513/ec2\_tag”, line 102, in main  
gettags = ec2.get\_all\_tags(filters=filters)  
File “/usr/local/Cellar/ansible/1.9.4/libexec/vendor/lib/python2.7/site-packages/boto/ec2/connection.py”, line 4179, in get\_all\_tags  
[(‘item’, Tag)], verb=‘POST’)  
File “/usr/local/Cellar/ansible/1.9.4/libexec/vendor/lib/python2.7/site-packages/boto/connection.py”, line 1170, in get\_list  
response = self.make\_request(action, params, path, verb)  
File “/usr/local/Cellar/ansible/1.9.4/libexec/vendor/lib/python2.7/site-packages/boto/connection.py”, line 1116, in make\_request  
return self.\_mexe(http\_request)  
File “/usr/local/Cellar/ansible/1.9.4/libexec/vendor/lib/python2.7/site-packages/boto/connection.py”, line 1028, in \_mexe  
raise BotoServerError(response.status, response.reason, body)  
boto.exception.BotoServerError: BotoServerError: 500 Internal Server Error

\<?xml version="1.0" encoding="UTF-8"?\>

`InternalError`An internal error has occurred0774638d-6961-49f8-ad60-8be66316e2d3

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![Rob\_Wilkerson](https://avatars.discourse-cdn.com/v4/letter/r/c67d28/32.png) [@Rob\_Wilkerson](https://forum.ansible.com/u/Rob_Wilkerson)\
**Post date:** [October 29, 2015, 3:19pm UTC](https://forum.ansible.com/t/incorrect-use-of-with-indexed-items/19651/2 "2015-10-29T15:19:46Z")

</div>

Oh noz. Punitive head slap for me.

- name: Instances | Tag each new instance with a name  
ec2\_tag:  
aws\_access\_key: “{{ awscli.access\_key }}”  
aws\_secret\_key: “{{ awscli.secret\_key }}”  
region: “{{ aws.region }}”  
resource: “{{ item.1 }}”  
state: present  
tags:  
Name: “{{ env\_short }}-{{ ‘ws%02d’ | format(item.0) }}”  
with\_indexed\_items: webservers.instance\_ids

When I switched to using with\_indexed\_items, I forgot to alter my original resource value to use the indexed value. Argh.
