Skip to content

Instantly share code, notes, and snippets.

@tkellen
Created December 19, 2015 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkellen/c3521685e4074b7b0099 to your computer and use it in GitHub Desktop.
Save tkellen/c3521685e4074b7b0099 to your computer and use it in GitHub Desktop.
simple dynamic inventory file for hookshot / ansible integration
#!/usr/bin/env python
import sys
import os
try:
import json
except ImportError:
import simplejson as json
GROUP = os.environ.get('ANSIBLE_GROUP', 'all')
HOST = os.environ.get('ANSIBLE_HOST')
if HOST is None:
raise Exception('Unable to generate inventory, ANSIBLE_HOST not present.')
exit(1)
inventory = {}
inventory[GROUP] = {}
inventory[GROUP]['hosts'] = [HOST]
if (len(sys.argv) == 2 and sys.argv[1] == "--list"):
print json.dumps(inventory, indent=2)
else:
print json.dumps({})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment