Skip to content

Instantly share code, notes, and snippets.

@zeitounator
Created August 23, 2023 14:00
Show Gist options
  • Save zeitounator/da8bb12b76401a5e2094cff4c979d5ee to your computer and use it in GitHub Desktop.
Save zeitounator/da8bb12b76401a5e2094cff4c979d5ee to your computer and use it in GitHub Desktop.
$ tree
.
└── inventories
├── children.yml
├── host.yml
├── otherhosts.yml
└── shared.yml
1 directory, 4 files
$ cat inventories/children.yml
---
testgroup:
children:
group1:
sharedservers:
$ cat inventories/host.yml
---
group1:
hosts:
host1:
host2:
$ cat inventories/otherhosts.yml
---
group2:
hosts:
hostA:
hostB:
$ cat inventories/shared.yml
---
sharedservers:
hosts:
host3:
host4:
$ ansible-inventory -i inventories/ --list
{
"_meta": {
"hostvars": {}
},
"all": {
"children": [
"ungrouped",
"testgroup",
"group2"
]
},
"group1": {
"hosts": [
"host1",
"host2"
]
},
"group2": {
"hosts": [
"hostA",
"hostB"
]
},
"sharedservers": {
"hosts": [
"host3",
"host4"
]
},
"testgroup": {
"children": [
"group1",
"sharedservers"
]
}
}
$ ansible -i inventories/ testgroup -m debug -a var=inventory_hostname
host4 | SUCCESS => {
"inventory_hostname": "host4"
}
host1 | SUCCESS => {
"inventory_hostname": "host1"
}
host2 | SUCCESS => {
"inventory_hostname": "host2"
}
host3 | SUCCESS => {
"inventory_hostname": "host3"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment