Skip to content

Instantly share code, notes, and snippets.

@tuxfight3r
Created March 10, 2016 13:08
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save tuxfight3r/2c027f8fd70333a8288e to your computer and use it in GitHub Desktop.
Save tuxfight3r/2c027f8fd70333a8288e to your computer and use it in GitHub Desktop.
Ansible dynamic inventory bash demo
#!/bin/bash
if [ "$1" == "--list" ] ; then
cat<<EOF
{
"bash_hosts": {
"hosts": [
"10.220.21.24",
"10.220.21.27"
],
"vars": {
"host_proxy_var": "proxy2"
}
},
"_meta": {
"hostvars": {
"10.220.21.24": {
"host_specific_var": "towerhost"
},
"10.220.21.27": {
"host_specific_var": "testhost"
}
}
}
}
EOF
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