Get all groups from parent group

25 views
Skip to first unread message

starflig...@t-online.de

unread,
Dec 12, 2017, 4:39:45 AM12/12/17
to Ansible Project
Hi guys,

I want to get all existent subgroups from a parent group.

Example Playbook:

---
- hosts: "test"

  tasks
:
 
- group_by:
     key
: "{{ansible_distribution}}-{{ansible_distribution_major_version}}"
     parents
: "dist"

 
- debug: var="{{ groups['dist'] }}"
    run_once
: true

#unfortunately I only get all the hosts of the parent group instead the groups created by 'group_by'

#Something like {% for group in groups['dist'] %} .... {% endfor %} ??
#or this:
 
- name: test
    command
: echo {{ item }}
    with_items
: "{{ groups['dist'] }}"
    delegate_to
: localhost
    run_once
: true

#-> only hosts... :-(


Any ideas?

Thanks,
starflighter

Ansible-Version:

ansible 2.4.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]


starflig...@t-online.de

unread,
Jan 16, 2018, 8:12:38 AM1/16/18
to Ansible Project
Any Updates here? :-(
I still need something like this...

starflig...@t-online.de

unread,
Jan 22, 2018, 9:25:34 AM1/22/18
to Ansible Project


I solved it myself:


  - group_by:
     key
: "dist_{{ansible_distribution.lower()}}-{{ansible_distribution_major_version}}"

 
- name: Hostname der Server pro Distribution
    debug
: var="groups['{{ item }}']"
    with_items
: "{{ groups.keys()|select('match', 'dist_.*')|list }}"
    run_once
: true


Reply all
Reply to author
Forward
0 new messages