terminating instances

31 views
Skip to first unread message

David Villasmil

unread,
May 10, 2018, 5:27:06 PM5/10/18
to Ansible Project
hello all,

I run "ec2_instance_facts" to get some instance_ids:

- ec2_instance_facts:
region: us-east-1
filters:
"tag:Name": "*{{ cluster }}*"
register: ec2_res


Then i can properly print the instance_ids only for those running:

- name: print ips
debug: "msg={{ item.instance_id }}"
with_items: "{{ ec2_res.instances }}"
when: item.state.name == "running"

_BUT_ I can't terminate them, i trying like this:

- name: Terminate instances that were previously launched
ec2:
state: "absent"
instance_ids: "{{ item.instance_id }}"
when: item.state.name == "running"
with_items: "{{ ec2_res.instances }}"


But this fails with:

fatal: [127.0.0.1]: FAILED! => {
    "msg": "The task includes an option with an undefined variable. The error was: 'item' is undefined\n\nThe error appears to have been in '/home/admin/voice-conf/playbooks/add_fs_to_cluster.yml': line 34, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n  - name: Terminate instances that were previously launched\n    ^ here\n"
}


some help is appreciated!

David

David Villasmil

unread,
May 11, 2018, 1:51:39 PM5/11/18
to Ansible Project
Anyone able to help?

Kai Stian Olstad

unread,
May 11, 2018, 2:24:54 PM5/11/18
to ansible...@googlegroups.com
On 11.05.2018 19:51, David Villasmil wrote:
> Anyone able to help?

Probably, but as you can see below your mail screwed up any
formatting...

> On Thursday, May 10, 2018 at 11:27:06 PM UTC+2, David Villasmil wrote:
>>
>> hello all,
>>
>> I run "ec2_instance_facts" to get some instance_ids:
>>
>> - ec2_instance_facts:
>> region: us-east-1
>> filters:
>> "tag:Name": "*{{ cluster }}*"
>> register: ec2_res

as you can see , no indentation at all.


>> But this fails with:
>>
>> fatal: [127.0.0.1]: FAILED! => {
>> "msg": "The task includes an option with an undefined variable.
>> The
>> error was: 'item' is undefined\n\nThe error appears to have been in
>> '/home/admin/voice-conf/playbooks/add_fs_to_cluster.yml': line 34,
>> column
>> 5, but may\nbe elsewhere in the file depending on the exact syntax
>> problem.\n\nThe offending line appears to be:\n\n\n - name: Terminate
>> instances that were previously launched\n ^ here\n"

This is probably a indentation problem, but since your mail all the
indentation is gone it's very hard to help.

--
Kai Stian Olstad

Tony Chia

unread,
May 11, 2018, 6:38:17 PM5/11/18
to Ansible Project
It seems the "when" for the ec2 task is not lined up. "when" should be indented at the same level as ec2 task similar to the debug task

David Villasmil

unread,
May 11, 2018, 6:46:29 PM5/11/18
to ansible...@googlegroups.com

Shit. Ok I'm not home now, but I'll try asap. And resend the email unformatted.

Thanks for replying, i appreciate it!


--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b3015d67-7e06-49b4-9390-daa98a548c28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages