Skip to content

Instantly share code, notes, and snippets.

@tkellen
Created December 19, 2015 21:05
Show Gist options
  • Save tkellen/c3521685e4074b7b0099 to your computer and use it in GitHub Desktop.
Save tkellen/c3521685e4074b7b0099 to your computer and use it in GitHub Desktop.

Revisions

  1. Tyler Kellen created this gist Dec 19, 2015.
    25 changes: 25 additions & 0 deletions pr.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/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({})