I have a playbook that's creating _n_ EC2 instances using exact_count. I'd 
like to tag those instances with a semi-meaningful Name value. I can get a 
list of all of my tagged instances from the ec2 module return value using 
{{ servers.tagged_instances }}, but...

I only want to apply a Name tag to those that don't already have one.

- name: Instances | Tag each instance with a name
  ec2_tag:
    aws_access_key: "{{ awscli.access_key }}"
    aws_secret_key: "{{ awscli.secret_key }}"
    region: "{{ aws.region }}"
    resource: "{{ item.1.id }}"
    state: present
    tags:
      Name: "{{ env_short }}-{{ 'ws%02d' | format(item.0) }}"
  with_indexed_items: webservers.tagged_instances
  when: "'Name' not in item.tags.keys()"  # Untagged instances only

I've tried several variations of the `when` stanza, but nothing's worked. 
Likewise, I haven't found any documentation with an example like this. Is 
it possible?

-- 
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/f917f2c7-f592-4ba3-9ebf-19bfb166fd0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to