# ansible all -i inventory.sh -m debug -a var=host_specific_var
host-a | SUCCESS => {
"host_specific_var": "abcde-a"
}
host-b | SUCCESS => {
"host_specific_var": "abcde-b"
}
host-c | SUCCESS => {
"host_specific_var": "abcde-c"
}
Last active
January 6, 2020 12:25
-
-
Save kvaps/ff9d1af9a09c22ed481a02af5a4b9627 to your computer and use it in GitHub Desktop.
ansible jsonnet proof of concept
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
#!/usr/bin/jsonnet | |
local host_specific_var = 'abcde'; | |
{ | |
jsonnet_hosts: { | |
hosts: [ | |
'host-a', | |
'host-b', | |
'host-c', | |
], | |
vars: { | |
common_var: 'host01-host02', | |
}, | |
}, | |
_meta: { | |
hostvars: { | |
[x]: { | |
host_specific_var: host_specific_var + '-' + std.split(x, '-')[1], | |
} | |
for x in $.jsonnet_hosts.hosts | |
}, | |
}, | |
} |
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
#!/bin/sh | |
dynamic_json_file=inventory.jsonnet | |
if [ "$1" == "--list" ] ; then | |
jsonnet ${dynamic_json_file} | |
elif [ "$1" == "--host" ]; then | |
echo '{"_meta": {"hostvars": {}}}' | |
else | |
echo "{ }" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment