Created
August 23, 2023 14:00
-
-
Save zeitounator/da8bb12b76401a5e2094cff4c979d5ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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