get all nodes of hostgroup within playbook

38 views
Skip to first unread message

gthie...@googlemail.com

unread,
Apr 26, 2017, 9:09:47 AM4/26/17
to Ansible Project
I need to workaround a bug in "virt_net" module when more then a network is created.

For this the task uses the iterates explicitly through all hosts of the group instead of performing the task in the context of the inventory_hostname:

- name: "gather neccessary libvirt networks"
  set_fact
: virt_networks="{{ virt_networks | default({}) | combine({hostvars[item].cidr:hostvars[item].network}) }}"
  with_items
:
       
"{{ libvirt.nodes }}"

libvirt.group is extra defined in the main variable section of my playbook and references manually the hosts group.

variables:
   
- libvirt:
        nodes
: "{{ groups['ovirtm'] }}"

Can I get the list of all nodes of my hostgroup without extra defining it in the vars section?

Only found that something like this works, but this may not return the correct group...

ansible -m debug -a msg="{{ groups[hostvars[inventory_hostname].group_names[0]] }}"


Reply all
Reply to author
Forward
0 new messages