I've got a playbook in which I'm trying to use add_host to dynamically generate a group of hosts. Here's what I have:
\roles
\ group_servers
\ tasks
\ main.yml
\ common
\ tasks
\ main.yml
setup.yml
==> ./roles/group_my_servers/tasks/main.yml
---
- name: Group My boxes
add_host: name={{ inventory_hostname }} group="my_servers"
===> ./setup.yml
---
- hosts: all
gather_facts: False
roles:
## create my_servers group
- role: group_my_servers
- hosts: my_servers
gather_facts: False
roles:
## bring servers to the baseline config
- role: common
One important note - inventory is dynamically generated and populates "
owner.name" with some values. That is confirmed to work just fine as far as I can tell.
What I get - above playbook only goes through the first "detected" box and skips the rest. If I use specific '--limit' to specify individual machines - it works fine, so invocation like:
work as expected. However:
$ ansible-playbook -vv --limit=mygroup1 -u root setup.yml
or
$ ansible-playbook -vv -u root setup.yml
process just the first host and do not add the rest of hosts to the group. What am I doing wrong?
In some other playbook I use "add_host" combined with "with_items" and it works as expected why here it doesn't?
It certainly feels like role is being applied only for one host and then Ansible decides not to run that role again... why?