ec2.instance_ids Invalid id

548 views
Skip to first unread message

Marc Peiser

unread,
Oct 18, 2013, 8:38:52 AM10/18/13
to ansible...@googlegroups.com
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 <module>
    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"?>
<Response><Errors><Error><Code>InvalidInstanceID.Malformed</Code><Message>Invalid id: "[u'i-29333566']"</Message></Error></Errors><RequestID>129f061b-da3e-4fa5-be80-9ad6493678f8</RequestID></Response>


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

Michael DeHaan

unread,
Oct 18, 2013, 9:33:46 AM10/18/13
to ansible...@googlegroups.com
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.




--
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 ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Marc Peiser

unread,
Oct 21, 2013, 5:03:17 AM10/21/13
to ansible...@googlegroups.com
Thanks Michael, that sorted my problem.

Regards,
Marc

Amir Hajizamani

unread,
Feb 5, 2014, 9:19:03 AM2/5/14
to ansible...@googlegroups.com
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

Adam Heath

unread,
Feb 5, 2014, 10:54:13 AM2/5/14
to ansible...@googlegroups.com
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.

On 02/05/2014 08:19 AM, Amir Hajizamani wrote:
> 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
>
> On Friday, 18 October 2013 14:33:46 UTC+1, Michael DeHaan wrote:
>
> 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.

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.
> <javascript:>.
> For more options, visit https://groups.google.com/groups/opt_out
> <https://groups.google.com/groups/opt_out>.
>
>
>
>
> --
> Michael DeHaan <mic...@ansibleworks.com <javascript:>>
> CTO, AnsibleWorks, Inc.
> http://www.ansibleworks.com/
>
> --
> 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 ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.

James Tanner

unread,
Feb 5, 2014, 11:14:51 AM2/5/14
to ansible...@googlegroups.com
"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.
Reply all
Reply to author
Forward
0 new messages