# ec2.instance\_ids Invalid id

**URL:** <https://forum.ansible.com/t/ec2-instance-ids-invalid-id/13716>\
**Category:** Ansible Project\
**Created:** [October 18, 2013, 12:38pm UTC](https://forum.ansible.com/t/ec2-instance-ids-invalid-id/13716 "2013-10-18T12:38:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc\_Peiser](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@Marc\_Peiser](https://forum.ansible.com/u/Marc_Peiser)\
**Post date:** [October 18, 2013, 12:38pm UTC](https://forum.ansible.com/t/ec2-instance-ids-invalid-id/13716/1 "2013-10-18T12:38:52Z")

</div>

Hi,

I’m trying to terminate an ec2 instance but I’m getting the following error:

PLAY [Terminate instance] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1]

TASK: [Terminate instances that were previously launched] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [127.0.0.1] =\> {“failed”: true, “parsed”: false}  
invalid output was: Traceback (most recent call last):  
File “/home/smartallocator/.ansible/tmp/ansible-1382099110.85-99795266100410/ec2”, line 1587, in   
main()  
File “/home/smartallocator/.ansible/tmp/ansible-1382099110.85-99795266100410/ec2”, line 637, in main  
(changed, instance\_dict\_array, new\_instance\_ids) = terminate\_instances(module, ec2, instance\_ids)  
File “/home/smartallocator/.ansible/tmp/ansible-1382099110.85-99795266100410/ec2”, line 543, in terminate\_instances  
for res in ec2.get\_all\_instances(instance\_ids):  
File “/usr/local/lib/python2.7/dist-packages/boto/ec2/connection.py”, line 539, in get\_all\_instances  
filters=filters, dry\_run=dry\_run)  
File “/usr/local/lib/python2.7/dist-packages/boto/ec2/connection.py”, line 609, in get\_all\_reservations  
[(‘item’, Reservation)], verb=‘POST’)  
File “/usr/local/lib/python2.7/dist-packages/boto/connection.py”, line 1117, in get\_list  
raise self.ResponseError(response.status, response.reason, body)  
boto.exception.EC2ResponseError: EC2ResponseError: 400 Bad Request

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

`InvalidInstanceID.Malformed`Invalid id: “[u’i-29333566’]”129f061b-da3e-4fa5-be80-9ad6493678f8

FATAL: all hosts have already failed – aborting

My play looks as follows:

- name: Terminate instance  
hosts: localhost  
connection: local  
tasks:
- name: Terminate instances that were previously launched  
local\_action:  
module: ec2  
state: ‘absent’  
instance\_ids: “{{ ec2.instance\_ids }}”  
region: eu-west-1

The example in the docs does not have quotes around the {{ ec2.instance\_ids }} variable but if I omit the quotes then that errors too:

ERROR: Syntax Error while loading YAML script, site.yml  
Note: The error may actually appear before this position: line 41, column 24

state: ‘absent’  
instance\_ids: {{ ec2.instance\_ids }}  
^

Any ideas? I’m running ansible 1.4 from source.

Thanks,  
Marc

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 18, 2013, 1:33pm UTC](https://forum.ansible.com/t/ec2-instance-ids-invalid-id/13716/2 "2013-10-18T13:33:46Z")

</div>

it says you have a YAML syntax error, so this is not an Ansible thing per se.

If you need to pass a reference you must still do it like this, and this is the only reason to ever do this.

instance\_ids: ${some\_list}

This will be going away in a future release once I bang on things a bit.

As for the YAML Syntax error, there’s some code to provide suggestions in 1.4, but it seems it was thrown off by the underscore. Curious.

---

<div class="post-metadata">

**Author:** ![Marc\_Peiser](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@Marc\_Peiser](https://forum.ansible.com/u/Marc_Peiser)\
**Post date:** [October 21, 2013, 9:03am UTC](https://forum.ansible.com/t/ec2-instance-ids-invalid-id/13716/3 "2013-10-21T09:03:17Z")

</div>

Thanks Michael, that sorted my problem.

Regards,  
Marc

---

<div class="post-metadata">

**Author:** ![Amir\_Hajizamani](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@Amir\_Hajizamani](https://forum.ansible.com/u/Amir_Hajizamani)\
**Post date:** [February 5, 2014, 2:19pm UTC](https://forum.ansible.com/t/ec2-instance-ids-invalid-id/13716/4 "2014-02-05T14:19:03Z")

</div>

Hi Michael,

Thanks for this, I also tripped up on this issue. I was about to prep and send a pull-request to update the docs for this, but wondered if there’s any point if this issue will be ironed out by the next release anyway?

A

---

<div class="post-metadata">

**Author:** ![adam2](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@adam2](https://forum.ansible.com/u/adam2)\
**Post date:** [February 5, 2014, 3:54pm UTC](https://forum.ansible.com/t/ec2-instance-ids-invalid-id/13716/5 "2014-02-05T15:54:13Z")

</div>

I'm guessing, but why does this module use local\_action, instead of delegate\_to: localhost? Maybe something in ansible is doing a double encode/decode with the complex nested data when local\_action is in use.

> Hi Michael,
> 
> Thanks for this, I also tripped up on this issue. I was about to prep  
> and send a pull-request to update the docs for this, but wondered if  
> there's any point if this issue will be ironed out by the next release  
> anyway?
> 
> A
> 
> &nbsp;&nbsp;&nbsp;&nbsp;it says you have a YAML syntax error, so this is not an Ansible  
> &nbsp;&nbsp;&nbsp;&nbsp;thing per se.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;If you need to pass a reference you must still do it like this, and  
> &nbsp;&nbsp;&nbsp;&nbsp;this is the only reason to ever do this.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;instance\_ids: ${some\_list}
> 
> &nbsp;&nbsp;&nbsp;&nbsp;This will be going away in a future release once I bang on things a bit.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;As for the YAML Syntax error, there's some code to provide  
> &nbsp;&nbsp;&nbsp;&nbsp;suggestions in 1.4, but it seems it was thrown off by the  
> &nbsp;&nbsp;&nbsp;&nbsp;underscore. Curious.

You aren't reading that right. He tried it twice, once with "", and once without. The time he tried it without, yaml was complaining about the {{. Count the leading spaces, and you'll get to column 24. At a guess, you are looking at some broken html rendering of the email, which is using a proportional font. When I went to reply to this, the error caret lined up correctly.

His real problem is when he tried it with "", and is shown in the ansible-doc output.

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [February 5, 2014, 4:14pm UTC](https://forum.ansible.com/t/ec2-instance-ids-invalid-id/13716/6 "2014-02-05T16:14:51Z")

</div>

"local\_action" and "delegate\_to: localhost" are very similar and work pretty much the same way, except for one big difference.

local\_action also implies the connection method is local, where as "delegate\_to: localhost" could use ssh/paramiko to connect to your local machine if those parameters are set in the inventory or if using "-c smart/ssh/paramiko". If the connection is not local, you loose your EC2/AWS\* environment variables that were set in your shell session. You could of course declare those variables with env: or by setting the parameters for the modules, but most of our doc examples reference setting environment variables.
