add_host madness... or role ...singletons??? what?

53 views
Skip to first unread message

Dmitry Makovey

unread,
Jun 11, 2015, 5:45:30 PM6/11/15
to ansible...@googlegroups.com
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?


Dmitry Makovey

unread,
Jun 11, 2015, 5:48:55 PM6/11/15
to ansible...@googlegroups.com
tested by moving add_host from role over to "tasks" - same result. Sounds like I'm missing the point someplace, but where?
Reply all
Reply to author
Forward
0 new messages