diff options
Diffstat (limited to 'lib/ansible/plugins/inventory/script.py')
-rw-r--r-- | lib/ansible/plugins/inventory/script.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/ansible/plugins/inventory/script.py b/lib/ansible/plugins/inventory/script.py index 4ffd8e1a..48d92343 100644 --- a/lib/ansible/plugins/inventory/script.py +++ b/lib/ansible/plugins/inventory/script.py @@ -28,6 +28,8 @@ DOCUMENTATION = ''' notes: - Enabled in configuration by default. - The plugin does not cache results because external inventory scripts are responsible for their own caching. + - To write your own inventory script see (R(Developing dynamic inventory,developing_inventory) from the documentation site. + - To find the scripts that used to be part of the code release, go to U(https://github.com/ansible-community/contrib-scripts/). ''' import os @@ -37,7 +39,7 @@ from collections.abc import Mapping from ansible.errors import AnsibleError, AnsibleParserError from ansible.module_utils.basic import json_dict_bytes_to_unicode -from ansible.module_utils._text import to_native, to_text +from ansible.module_utils.common.text.converters import to_native, to_text from ansible.plugins.inventory import BaseInventoryPlugin from ansible.utils.display import Display @@ -187,7 +189,11 @@ class InventoryModule(BaseInventoryPlugin): sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) except OSError as e: raise AnsibleError("problem running %s (%s)" % (' '.join(cmd), e)) - (out, err) = sp.communicate() + (out, stderr) = sp.communicate() + + if sp.returncode != 0: + raise AnsibleError("Inventory script (%s) had an execution error: %s" % (path, to_native(stderr))) + if out.strip() == '': return {} try: |