Skip to content

Instantly share code, notes, and snippets.

@AlBichutsky
Forked from tuxfight3r/inventory.sh
Created January 28, 2021 07:56
Show Gist options
  • Save AlBichutsky/9df94e4c5fd0c6cb98f26ac226878c71 to your computer and use it in GitHub Desktop.
Save AlBichutsky/9df94e4c5fd0c6cb98f26ac226878c71 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