Skip to content

Instantly share code, notes, and snippets.

@rockaut
Created December 14, 2021 18:53
Show Gist options
  • Save rockaut/73e8ee1c6c105405191c519004ec0360 to your computer and use it in GitHub Desktop.
Save rockaut/73e8ee1c6c105405191c519004ec0360 to your computer and use it in GitHub Desktop.
Ansible-Inventory YAML Anchor
---
all:
vars:
ansible_connection: local
children:
grp_a:
hosts: &grp_a
hosta1:
hosta2:
grp_b:
hosts: &grp_b
hostb1:
hostb2:
grp_ab:
hosts:
<<: *grp_a
<<: *grp_b
...
# ansible-inventory --list -i hosts.yml
{
"_meta": {
"hostvars": {
"hosta1": {
"ansible_connection": "local"
},
"hosta2": {
"ansible_connection": "local"
},
"hostb1": {
"ansible_connection": "local"
},
"hostb2": {
"ansible_connection": "local"
}
}
},
"all": {
"children": [
"grp_a",
"grp_ab",
"grp_b",
"ungrouped"
]
},
"grp_a": {
"hosts": [
"hosta1",
"hosta2"
]
},
"grp_ab": {
"hosts": [
"hosta1",
"hosta2",
"hostb1",
"hostb2"
]
},
"grp_b": {
"hosts": [
"hostb1",
"hostb2"
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment