| 1 |
# Additional ClusterShell group source config file |
| 2 |
# |
| 3 |
# Please see `man 5 groups.conf` for further details. |
| 4 |
# |
| 5 |
|
| 6 |
# Ansible inventory bindings |
| 7 |
# |
| 8 |
# Requirements: ansible-core (provides ansible-inventory), jq |
| 9 |
# |
| 10 |
# Replace /path/to/inventory with your inventory path or directory, |
| 11 |
# or set ANSIBLE_INVENTORY in your environment to override it. |
| 12 |
# |
| 13 |
# Hostnames can be post-processed in jq, for instance to strip a DNS domain |
| 14 |
# suffix; see the Ansible inventory bindings section of the online docs. |
| 15 |
# |
| 16 |
[ansible] |
| 17 |
|
| 18 |
# Resolve group members, recursing into child groups |
| 19 |
map: ANSIBLE_INVENTORY="${ANSIBLE_INVENTORY:-/path/to/inventory}" ansible-inventory --list 2>/dev/null | jq -r --arg g "$GROUP" 'def r(d;g): (d[g].hosts//[])[], ((d[g].children//[])[] as $c | r(d;$c)); r(.;$g)' |
| 20 |
|
| 21 |
# Resolve all groups in a single call, recursing into child groups |
| 22 |
mapall: ANSIBLE_INVENTORY="${ANSIBLE_INVENTORY:-/path/to/inventory}" ansible-inventory --list 2>/dev/null | jq -r 'def r(d;g): (d[g].hosts//[])[], ((d[g].children//[])[] as $c | r(d;$c)); . as $d | keys[] | select(. != "_meta" and . != "all" and (test("[[:space:]:]") | not)) | "\(.): \([r($d;.)] | join(" "))"' |
| 23 |
|
| 24 |
# All inventory hosts |
| 25 |
all: ANSIBLE_INVENTORY="${ANSIBLE_INVENTORY:-/path/to/inventory}" ansible-inventory --list 2>/dev/null | jq -r '.[].hosts // empty | .[]' |
| 26 |
|
| 27 |
# All groups |
| 28 |
list: ANSIBLE_INVENTORY="${ANSIBLE_INVENTORY:-/path/to/inventory}" ansible-inventory --list 2>/dev/null | jq -r 'keys[] | select(. != "_meta" and . != "all")' |