Commit c6c3ce66 by Ferry Boender

Output proper JSON from vbox dynamic inventory contrib script

parent 6dd38c2a
...@@ -23,6 +23,11 @@ try: ...@@ -23,6 +23,11 @@ try:
except ImportError: except ImportError:
import simplejson as json import simplejson as json
class SetEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, set):
return list(obj)
return json.JSONEncoder.default(self, obj)
VBOX="VBoxManage" VBOX="VBoxManage"
...@@ -110,5 +115,4 @@ if __name__ == '__main__': ...@@ -110,5 +115,4 @@ if __name__ == '__main__':
else: else:
inventory = get_hosts() inventory = get_hosts()
import pprint sys.stdout.write(json.dumps(inventory, indent=2, cls=SetEncoder))
pprint.pprint(inventory)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment