Just in case someone else had similar problem, the solution was to add
"serial: 1" to the playbook otherwise the execution is parallel thus only
the last host preprocessed ends up in the group.
Simple example /etc/ansible/hosts-group inventory:
[group-tomcat]
10.22.0.43server_name=app11 ec2_
Thanks Michael your suggestions noted. I did some more testing and looks
like only one single instance, assuming the last instance, from the
inventory is being added to the group, and this is without any conditions.
Very simple playbook example:
---
- hosts: ec2
gather_facts: False
connect
A few things to cleanup first:
" - add_host: hostname={{ hostvars[inventory_hostname]['ec2_publicIp']
}} groupname=ec2hosts server_name={{
hostvars[inventory_hostname]['ec2_public_dns_name']
}}"
When you get ginormous variables like this, slow down, and define useful
shortcuts in your "vars"
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=ec2h