Created
December 19, 2015 21:05
-
-
Save tkellen/c3521685e4074b7b0099 to your computer and use it in GitHub Desktop.
simple dynamic inventory file for hookshot / ansible integration
This file contains hidden or 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/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