Make inventory plugin errors visible

When an inventory plugin fails with a nonzero exit status, Ansible
only prints stderr output.[1]  Make sure any exceptions we handle
print to stderr so we see what is wrong.

[1] - https://github.com/ansible/ansible/blob/devel/lib/ansible/inventory/script.py#L54

Closes-Bug: #1473221
Change-Id: Ifb1956811c851b44e09481253d58b0c673d13f8b
This commit is contained in:
stephane 2015-07-09 14:19:05 -07:00
parent 8aafb29107
commit 3e2ecdb07e

View File

@ -326,14 +326,14 @@ def main():
config = _parse_config()
if not config.list:
print("ERROR: This program must be executed in list mode.")
LOG.error("This program must be executed in list mode.")
exit(1)
(groups, hostvars) = _prepare_inventory()
if 'BIFROST_INVENTORY_SOURCE' not in os.environ:
print('ERROR: Please define a BIFROST_INVENTORY_SOURCE environment '
'variable with a comma separated list of data sources')
LOG.error('Please define a BIFROST_INVENTORY_SOURCE environment'
'variable with a comma separated list of data sources')
exit(1)
try:
@ -345,7 +345,7 @@ def main():
groups,
hostvars)
except Exception as e:
LOG.debug("File does not appear to be JSON or YAML - %s" % e)
LOG.error("File does not appear to be JSON or YAML - %s" % e)
try:
(groups, hostvars) = _process_baremetal_csv(
data_source,
@ -354,24 +354,24 @@ def main():
except Exception as e:
LOG.debug("CSV fallback processing failed, "
"received: &s" % e)
print("ERROR: BIFROST_INVENTORY_SOURCE does not "
"define a file that could be processed: "
"Tried JSON, YAML, and CSV formats")
LOG.error("BIFROST_INVENTORY_SOURCE does not define "
"a file that could be processed: "
"Tried JSON, YAML, and CSV formats")
exit(1)
elif "ironic" in data_source:
if SHADE_LOADED:
(groups, hostvars) = _process_shade(groups, hostvars)
else:
print("ERROR: BIFROST_INVENTORY_SOURCE is set to ironic "
"however the shade library failed to load, and may "
"not be present.")
LOG.error("BIFROST_INVENTORY_SOURCE is set to ironic "
"however the shade library failed to load, and may "
"not be present.")
exit(1)
else:
print('ERROR: BIFROST_INVENTORY_SOURCE does not define a file')
LOG.error('BIFROST_INVENTORY_SOURCE does not define a file')
exit(1)
except Exception as error:
print('ERROR: Failed processing: %s' % error)
LOG.error('Failed processing: %s' % error)
exit(1)
# General Data Conversion