Thanks Tom!
It works, but I do not understand how or why :)
On Thursday, January 15, 2015 at 4:01:12 PM UTC+2, Tom Bamford wrote:
>
> Hi Tzach
>
> I usually approach instance termination by matching the instances with ec2
> dynamic inventory, then add them to a group and terminate them in another
> play targeted at the newly created group, based on their instance id (which
> is automatically added as an inventory variable by the ec2 inventory
> script).
>
> Note that I specify gather_facts: false and do not reference the hostvars
> dictionary. That way, Ansible does not attempt or need to reach the
> instances via ssh before it is able to terminate them.
>
> - name: Find sandbox instance(s) with matching name
> hosts: tag_Name_Test
> gather_facts: false
> tasks:
>
> - name: Create group
> group_by: key=legacy
>
> This create a host group called Legacy
>
>
> - hosts: legacy
>
> This use the legacy group, so why cant I use the tag_Name_Test directly?
>
> connection: local
>
> Why this play have connection: local and first does not?
>
> gather_facts: false
> tasks:
>
> - name: Terminate instance(s)
> ec2:
> instance_ids: "{{ ec2_id }}"
>
> region: {{ region }} is also required
>
> state: absent
>
> Hope this helps.
>
And last: can I use two different tag name, and merge them somehow?
> Tom
>
> On 15 January 2015 at 15:22, Tzach Livyatan <[email protected]
> <javascript:>> wrote:
>
> Thanks Alex
>> This works, but my end goal is to use the list in a playbook.
>>
>> A similar example I'm struggling with:
>> Terminate all EC2 instances with a specific name.
>> I come up with the following:
>> ---
>> - name: Terminate EC2 instances with name Test
>> hosts: 127.0.0.1
>> connection: local
>> vars:
>> tasks:
>> - action: ec2_facts
>> - debug: msg="{{ hostvars[item]['ec2_id'] }}"
>> with_items:
>> groups['tag_Name_Cassandra']
>> - name: Terminate instances
>> local_action:
>> module: ec2
>> region: "{{region}}"
>> keypair: "{{key_name}}"
>> instance_ids: hostvars[{{ item }} ]['ec2_id']
>> with_items: groups['tag_Name_Test']
>> state: 'stopped'
>> wait: yes
>>
>> - name: Give everyone a minute
>> pause: minutes=1
>>
>>
>> The list is available in the debug message, but the following fail
>> instance_ids: hostvars[{{ item }} ]['ec2_id']
>> with_items: groups['tag_Name_Test']
>> with
>> 'item' is undefined
>>
>> I have try all combinations of curly-brace but nothing seems to work.
>> In a similar way, I want to use the internal IP list as parameter for
>> other task.
>>
>> Thanks
>> Tzach
>>
>>
>>
>>
>>
>>
>>
>> On Wednesday, January 14, 2015 at 3:26:32 PM UTC+2, Alex Clifford wrote:
>>>
>>> The following AWS CLI command will give you a list of all internal IPs
>>> (which you could run only against the Test host group):
>>>
>>> aws ec2 describe-instances --query 'Reservations[*].Instances[*].
>>> PrivateIpAddress' --output text
>>>
>>>
>>> On Wednesday, 14 January 2015 20:47:21 UTC+11, Tzach Livyatan wrote:
>>>>
>>>> Another newbie questions (second and last for today, I promise)
>>>> I have two groups for EC2 instances:
>>>> - Test servers
>>>> - Loader servers
>>>> each with a different tag.
>>>> I would like to get the list of the internal_ip of the Test group, and
>>>> use it to run a command on the Loaders group.
>>>> Any pointer will be appreciated!
>>>>
>>>> Thanks
>>>>
>>>> --
>> 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 [email protected] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/6c9e08aa-43d7-4329-a91c-a4a0b4f3f0e1%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/6c9e08aa-43d7-4329-a91c-a4a0b4f3f0e1%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/4b71eaa4-5c04-444b-a217-0029694b0936%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.