I think those variables are documented in the ec2 dynamic inventory
script. I don't now if there's a way to only add a tag, but you could
try using a different group in your hosts line, e.g., try selecting
your hosts based in another tag value besides Name. Or you may be able
to limit this task with a "when" clause using variables defined by the
ec2 script, but I never tested this.

On Wed, Apr 1, 2015 at 8:02 AM, Kegan Holtzhausen
<[email protected]> wrote:
> The tag command works, but it seems to re-tag all my instances who match the
> filter. Is there something I need to do to "add" tags only?
>
> I am trying to tag nodes which I deploy specific hazelcuts applications to
> in order to setup hz cluster detection.
>
> /K
>
> On Tuesday, March 31, 2015 at 6:01:53 PM UTC+2, Ivan Sichmann wrote:
>>
>> On Tue, Mar 31, 2015 at 10:16 AM, Kegan Holtzhausen
>> <[email protected]> wrote:
>>
>> > Example
>> >
>> > ---
>> > - name: tag something
>> >   vars:
>> >     tag_name: ami_test
>> >   hosts: "tag_Name_{{tag_name}}"
>> >   user: admin
>> >   tasks:
>> >     - name: Add tag to instances
>> >       local_action: ec2_tag resource="{{item.id}}"
>> > region="{{aws_region}}"
>> > state=present
>> >       with_items: ec2.instances
>> >       args:
>> >         tags:
>> >           Name: "{{tag_name}}"
>>
>> The ec2 (and hence the ec2.instance) variable is not defined in this
>> scope, it only exists after the task responsible for creating a new
>> instance is completed successfully.
>>
>> To tag existing instances with hosts from EC2, you can use the ec2_id
>> variable defined by the aws dynamic inventory script. For example:
>>
>> ---
>> - hosts:
>>     - tag_Name_{{tag_name}}
>>   user: ec2-user
>>   tasks:
>>     - name: Tag instances
>>       sudo: False
>>       local_action: >
>>         ec2_tag
>>         resource="{{ ec2_id }}"
>>         region=sa-east-1
>>         state=present
>>         aws_access_key={{ lookup('env', 'AWS_ACCESS_KEY_ID') }}
>>         aws_secret_key={{ lookup('env', 'AWS_SECRET_ACCESS_KEY') }}
>>       args:
>>         tags:
>>           Name: "{{ tag_name }}"
>>
>> --
>> Ivan Sichmann Freitas
>
> --
> 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/ad11a9c6-7cc3-4fae-b0c9-5e306a8cbeaf%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



-- 
Ivan Sichmann Freitas

-- 
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/CAG2tFJzkkxjfGGDJDxb8ND0a%2BCw5VKAO4z9Z%3D7S0zNWmS0KY8A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to