2012-04-13 18:50:30 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import json
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from optparse import OptionParser
|
|
|
|
|
|
|
|
parser = OptionParser()
|
|
|
|
parser.add_option('-l', '--list', default=False, dest="list_hosts", action="store_true")
|
|
|
|
parser.add_option('-H', '--host', default=None, dest="host")
|
|
|
|
parser.add_option('-e', '--extra-vars', default=None, dest="extra")
|
|
|
|
|
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
|
|
|
systems = {
|
2012-10-10 16:17:24 +00:00
|
|
|
"ungrouped": [ "jupiter", "saturn" ],
|
2012-04-13 18:50:30 +00:00
|
|
|
"greek": [ "zeus", "hera", "poseidon" ],
|
2012-10-10 16:35:45 +00:00
|
|
|
"norse": [ "thor", "odin", "loki" ],
|
|
|
|
"major-god": [ "zeus", "odin" ],
|
2012-04-13 18:50:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
variables = {
|
|
|
|
"thor": {
|
|
|
|
"hammer": True
|
2012-10-10 16:35:45 +00:00
|
|
|
},
|
|
|
|
"zeus": {},
|
2012-04-13 18:50:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if options.list_hosts == True:
|
|
|
|
print json.dumps(systems)
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
if options.host is not None:
|
|
|
|
if options.extra:
|
|
|
|
k,v = options.extra.split("=")
|
|
|
|
variables[options.host][k] = v
|
2014-09-11 16:26:54 +00:00
|
|
|
if options.host in variables:
|
|
|
|
print json.dumps(variables[options.host])
|
|
|
|
else:
|
|
|
|
print "{}"
|
2012-04-13 18:50:30 +00:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
parser.print_help()
|
2014-09-11 16:26:54 +00:00
|
|
|
sys.exit(1)
|