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"
when: owner.name == "owner1"
===> ./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:
$ ansible-playbook -vv --limit=my1.server.com -u root setup.yml
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?
--
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/a9f92c00-0909-49c1-8b3d-bd93265fd9c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.