inventory: Fail on non-existing limit file (#59758)

Ansible now fails with error message when user provides
non-existing limit file.

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2019-12-12 09:09:40 +05:30 committed by GitHub
parent b349ec8fcf
commit 41e19a4058
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 3 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- Ansible should fail with error when non-existing limit file is provided in command line.

View file

@ -618,10 +618,15 @@ class InventoryManager(object):
results = []
# allow Unix style @filename data
for x in subset_patterns:
if not x:
continue
if x[0] == "@":
fd = open(x[1:])
results.extend([to_text(l.strip()) for l in fd.read().split("\n")])
fd.close()
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)
with open(b_limit_file) as fd:
results.extend([to_text(l.strip()) for l in fd.read().split("\n")])
else:
results.append(to_text(x))
self._subset = results

View file

@ -21,6 +21,13 @@ if [ "$?" != "1" ]; then
exit 1
fi
# Ensure that non-existing limit file causes failure with rc 1
ansible-playbook -i ../../inventory --limit @foo playbook.yml
if [ "$?" != "1" ]; then
echo "Non-existing limit file should cause failure"
exit 1
fi
# Ensure that non-matching limit causes failure with rc 1
ansible-playbook -i ../../inventory --limit @"${empty_limit_file}" playbook.yml