diff options
author | Rick Elrod <rick@elrod.me> | 2021-02-22 22:18:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-22 22:18:23 +0100 |
commit | fa046d302c0e352a8dfaa8d5d364eeca7e815afd (patch) | |
tree | 20416ba2c58e07be6d600f16ceb87cddba9fb3ed /lib | |
parent | Minor Doc Update to password.py (#73468) (diff) | |
download | ansible-fa046d302c0e352a8dfaa8d5d364eeca7e815afd.tar.xz ansible-fa046d302c0e352a8dfaa8d5d364eeca7e815afd.zip |
[InventoryManager] Fix two unhandled exceptions (#73667)
Change:
- Fix regression: unhandled exception when given inventory directory
is empty or contains empty subdirectories.
- Fix unhandled exception when limit file is actually a directory
instead of a file.
- Fix inventory tests which previously could never fail due to missing
`set -e`. Fixed up tests that failed after `set -e` was added. Added
several tests.
Test Plan:
- New tests
- Fixed existing tests which previously could never fail
Tickets:
- Fixes #73658
Signed-off-by: Rick Elrod <rick@elrod.me>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ansible/inventory/manager.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/ansible/inventory/manager.py b/lib/ansible/inventory/manager.py index 3e70ee48b7..71745b0b28 100644 --- a/lib/ansible/inventory/manager.py +++ b/lib/ansible/inventory/manager.py @@ -244,6 +244,7 @@ class InventoryManager(object): ''' Generate or update inventory for the source provided ''' parsed = False + failures = [] display.debug(u'Examining possible inventory source: %s' % source) # use binary for path functions @@ -272,7 +273,6 @@ class InventoryManager(object): self._inventory.current_source = source # try source with each plugin - failures = [] for plugin in self._fetch_inventory_plugins(): plugin_name = to_text(getattr(plugin, '_load_name', getattr(plugin, '_original_path', ''))) @@ -635,6 +635,8 @@ class InventoryManager(object): b_limit_file = to_bytes(x[1:]) if not os.path.exists(b_limit_file): raise AnsibleError(u'Unable to find limit file %s' % b_limit_file) + if not os.path.isfile(b_limit_file): + raise AnsibleError(u'Limit starting with "@" must be a file, not a directory: %s' % b_limit_file) with open(b_limit_file) as fd: results.extend([to_text(l.strip()) for l in fd.read().split("\n")]) else: |