mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-28 19:20:22 -07:00
parent
16c2207d21
commit
758cfeb73e
4 changed files with 23 additions and 22 deletions
|
@ -4,6 +4,7 @@ import argparse
|
||||||
from ipalib import api
|
from ipalib import api
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
def initialize():
|
def initialize():
|
||||||
'''
|
'''
|
||||||
This function initializes the FreeIPA/IPA API. This function requires
|
This function initializes the FreeIPA/IPA API. This function requires
|
||||||
|
@ -21,6 +22,7 @@ def initialize():
|
||||||
|
|
||||||
return api
|
return api
|
||||||
|
|
||||||
|
|
||||||
def list_groups(api):
|
def list_groups(api):
|
||||||
'''
|
'''
|
||||||
This function prints a list of all host groups. This function requires
|
This function prints a list of all host groups. This function requires
|
||||||
|
@ -51,6 +53,7 @@ def list_groups(api):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
'''
|
'''
|
||||||
This function parses the arguments that were passed in via the command line.
|
This function parses the arguments that were passed in via the command line.
|
||||||
|
@ -66,6 +69,7 @@ def parse_args():
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def print_host(host):
|
def print_host(host):
|
||||||
'''
|
'''
|
||||||
This function is really a stub, it could return variables to be used in
|
This function is really a stub, it could return variables to be used in
|
||||||
|
@ -79,6 +83,7 @@ def print_host(host):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import json
|
|
||||||
import requests
|
|
||||||
import os
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import requests
|
||||||
import types
|
import types
|
||||||
|
|
||||||
RACKHD_URL = 'http://localhost:8080'
|
RACKHD_URL = 'http://localhost:8080'
|
||||||
|
|
||||||
|
|
||||||
class RackhdInventory(object):
|
class RackhdInventory(object):
|
||||||
def __init__(self, nodeids):
|
def __init__(self, nodeids):
|
||||||
self._inventory = {}
|
self._inventory = {}
|
||||||
for nodeid in nodeids:
|
for nodeid in nodeids:
|
||||||
self._load_inventory_data(nodeid)
|
self._load_inventory_data(nodeid)
|
||||||
inventory = {}
|
inventory = {}
|
||||||
for nodeid,info in self._inventory.items():
|
for (nodeid, info) in self._inventory.items():
|
||||||
inventory[nodeid] = (self._format_output(nodeid, info))
|
inventory[nodeid] = (self._format_output(nodeid, info))
|
||||||
print(json.dumps(inventory))
|
print(json.dumps(inventory))
|
||||||
|
|
||||||
|
@ -24,7 +25,7 @@ class RackhdInventory(object):
|
||||||
info['lookup'] = RACKHD_URL + '/api/common/lookups/?q={0}'.format(nodeid)
|
info['lookup'] = RACKHD_URL + '/api/common/lookups/?q={0}'.format(nodeid)
|
||||||
|
|
||||||
results = {}
|
results = {}
|
||||||
for key,url in info.items():
|
for (key, url) in info.items():
|
||||||
r = requests.get(url, verify=False)
|
r = requests.get(url, verify=False)
|
||||||
results[key] = r.text
|
results[key] = r.text
|
||||||
self._inventory[nodeid] = results
|
self._inventory[nodeid] = results
|
||||||
|
@ -36,7 +37,7 @@ class RackhdInventory(object):
|
||||||
if len(node_info) > 0:
|
if len(node_info) > 0:
|
||||||
ipaddress = node_info[0]['ipAddress']
|
ipaddress = node_info[0]['ipAddress']
|
||||||
output = {'hosts': [ipaddress], 'vars': {}}
|
output = {'hosts': [ipaddress], 'vars': {}}
|
||||||
for key,result in info.items():
|
for (key, result) in info.items():
|
||||||
output['vars'][key] = json.loads(result)
|
output['vars'][key] = json.loads(result)
|
||||||
output['vars']['ansible_ssh_user'] = 'monorail'
|
output['vars']['ansible_ssh_user'] = 'monorail'
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
|
@ -426,7 +426,7 @@ class VMWareInventory(object):
|
||||||
# Reset the inventory keys
|
# Reset the inventory keys
|
||||||
for k, v in name_mapping.items():
|
for k, v in name_mapping.items():
|
||||||
|
|
||||||
if not host_mapping or not k in host_mapping:
|
if not host_mapping or k not in host_mapping:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# set ansible_host (2.x)
|
# set ansible_host (2.x)
|
||||||
|
@ -742,5 +742,3 @@ class VMWareInventory(object):
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Run the script
|
# Run the script
|
||||||
print(VMWareInventory().show())
|
print(VMWareInventory().show())
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
contrib/inventory/freeipa.py
|
|
||||||
contrib/inventory/rackhd.py
|
|
||||||
contrib/inventory/vmware_inventory.py
|
|
||||||
lib/ansible/cli/__init__.py
|
lib/ansible/cli/__init__.py
|
||||||
lib/ansible/cli/adhoc.py
|
lib/ansible/cli/adhoc.py
|
||||||
lib/ansible/cli/console.py
|
lib/ansible/cli/console.py
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue