client-pull-installation/ansdyninv.py

33 lines
827 B
Python
Raw Normal View History

#!/usr/bin/env python
# vim:sts=2:sw=2
from argparse import ArgumentParser
2015-09-07 19:12:03 +00:00
from os import popen
import requests
2015-09-07 19:12:03 +00:00
parser=ArgumentParser()
parser.add_argument('--list', help="Returns a JSON dictionary of all the groups to be managed.", action="store_true")
parser.add_argument('--host', nargs='?', help="Returns an empty JSON dictionary.")
2015-09-07 19:12:03 +00:00
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:
2015-09-07 19:12:03 +00:00
r = requests.get("http://" + srv + ":3000/ansible_list")
if r.status_code != 200:
sys.exit(1)
print r.text
if args.host:
2015-09-07 19:12:03 +00:00
r = requests.get("http://" + srv + ":3000/ansible_host")
if r.status_code != 200:
sys.exit(1)
print r.text