Skip to content

Instantly share code, notes, and snippets.

@s-hertel
Created October 21, 2020 20:17
Show Gist options
  • Save s-hertel/14b57b8ffa6f1473900ed81fadf724c4 to your computer and use it in GitHub Desktop.
Save s-hertel/14b57b8ffa6f1473900ed81fadf724c4 to your computer and use it in GitHub Desktop.
test composing variables
# add hosts and hostvars to inventory with the yaml inventory plugin
all:
hosts:
host1:
a: 'is_defined'
host2:
# compose variables from the hosts in inventory
plugin: constructed
compose:
var: a is defined | ternary('is_defined', 'is_not_defined')
$ ansible-inventory -i inventory_source_1.yml -i inventory_source_2.yml --list
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly
changing source of code and can become unstable at any point.
{
"_meta": {
"hostvars": {
"host1": {
"a": "is_defined",
"var": "is_defined"
},
"host2": {
"var": "is_not_defined"
}
}
},
"all": {
"children": [
"ungrouped"
]
},
"ungrouped": {
"hosts": [
"host1",
"host2"
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment