ec2.instance_ids Invalid id

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.MalformedInvalid 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

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.

Thanks Michael, that sorted my problem.

Regards,
Marc

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

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

    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.

"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.