Hi all,

I have the following playbook trying to create a subgroup out of my ec2 
dynamic inventory with instances matching given tags: 

---
- hosts: ec2 
  gather_facts: False
  connection: local
  tasks:
     - add_host: hostname={{ hostvars[inventory_hostname]['ec2_publicIp'] 
}} groupname=ec2hosts server_name={{ 
hostvars[inventory_hostname]['ec2_public_dns_name'] }}
       when: hostvars[inventory_hostname]['ec2_region'] == 'ap-southeast-2' 
             and hostvars[inventory_hostname]['ec2_tag_Role'] ~ 
'application' 
             and hostvars[inventory_hostname]['ec2_tag_Type'] == 'tomcat'

- hosts: ec2hosts
  gather_facts: True
  remote_user: user1
  sudo: True
  tasks:
    # fetch instance data from the metadata servers in ec2
    - ec2_facts:

    # show all known facts for this host
    - debug: var=hostvars[inventory_hostname]

    # just show the instance-id
    - debug: msg="{{ 
hostvars[inventory_hostname]['ansible_ec2_instance-id'] }}"


This is the result of its run:

PLAY [ec2] 
******************************************************************** 

TASK: [add_host hostname={{hostvars[inventory_hostname]['ec2_publicIp']}} 
groupname=ec2hosts 
server_name={{hostvars[inventory_hostname]['ec2_public_dns_name']}}] *** 
skipping: [54.72.64.112]

PLAY [ec2hosts] 
*************************************************************** 
skipping: no hosts matched


The instances are being picked up correctly, I confirmed that with debug 
output, but looks like the group is not being populated correctly. I'm 
probably missing something here since looks like the supposed loop is not 
happening.

Can anyone spot what am I doing wrong here?

Thanks,
Igor

-- 
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/dd9eb356-287a-49ed-81cc-465623a4aa77%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to