Hi All,

I have an requirement to execute specific ansible task based on the ec2 
tags thats been injected in the instance. I am using ansible version 2.2.

Can someone let me know how can I get the list of ec2 tags? Below is the 
code snippet that I am trying to execute.

Code:

---
- hosts: "{{ host }}"
  tasks:
  - name: Display the hostname
    shell: hostname
  - debug:
      msg: "{{ host }}"
  - ec2_facts:
  - set_fact:
      in_id: "{{ ansible_ec2_instance_id }}"
      rg_id: "{{ ec2_region }}"
  - name: Retrieve all tags on an instance
    ec2_tag:
      resource: '{{ in_id }}'
      region: '{{ rg_id }}'
      state: list
    register: ec2_tags
  - name: List tags, such as Name and env
    debug:
      msg: "{{ ec2_tags.tags.Environment }}"

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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/0a9c2da2-5200-4828-b57b-3dbf3718ae96%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to