Updated ansdyninv.py.
This commit is contained in:
parent
4154bf5100
commit
ce71b22055
16
ansdyninv.py
16
ansdyninv.py
@ -2,6 +2,7 @@
|
||||
# vim:sts=2:sw=2
|
||||
|
||||
from argparse import ArgumentParser
|
||||
from os import popen
|
||||
import requests
|
||||
|
||||
parser=ArgumentParser()
|
||||
@ -9,12 +10,23 @@ parser.add_argument('--list', help="Returns a JSON dictionary of all the groups
|
||||
parser.add_argument('--host', nargs='?', help="Returns an empty JSON dictionary.")
|
||||
args=parser.parse_args()
|
||||
|
||||
# Simplifying, since we haven't already installed domain.yml, we assume to use
|
||||
# default gateway IP.
|
||||
gwt=popen("ip route show | grep ^default")
|
||||
data=gwt.read()
|
||||
gwt.close()
|
||||
srv=data.split()[2]
|
||||
|
||||
if args.list:
|
||||
r = requests.get("http://localhost:3000/ansible_inventory")
|
||||
r = requests.get("http://" + srv + ":3000/ansible_list")
|
||||
if r.status_code != 200:
|
||||
sys.exit(1)
|
||||
|
||||
print r.text
|
||||
|
||||
if args.host:
|
||||
print "{}"
|
||||
r = requests.get("http://" + srv + ":3000/ansible_host")
|
||||
if r.status_code != 200:
|
||||
sys.exit(1)
|
||||
|
||||
print r.text
|
||||
|
Loading…
x
Reference in New Issue
Block a user