inventory: Handle IndexError while parsing limit file (#59776)

Handle IndexError exception raised while parsing the limit file.

Fixes: #59695

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2019-07-30 22:32:17 +05:30 committed by Brian Coca
parent 8a6c7a97cc
commit 2ebc4e1e7e
3 changed files with 20 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- Handle IndexError while parsing empty limit file (https://github.com/ansible/ansible/issues/59695).

View file

@ -69,11 +69,14 @@ def order_patterns(patterns):
pattern_intersection = [] pattern_intersection = []
pattern_exclude = [] pattern_exclude = []
for p in patterns: for p in patterns:
if not p:
continue
if p[0] == "!": if p[0] == "!":
pattern_exclude.append(p) pattern_exclude.append(p)
elif p[0] == "&": elif p[0] == "&":
pattern_intersection.append(p) pattern_intersection.append(p)
elif p: else:
pattern_regular.append(p) pattern_regular.append(p)
# if no regular pattern was given, hence only exclude and/or intersection # if no regular pattern was given, hence only exclude and/or intersection

View file

@ -2,6 +2,17 @@
set -x set -x
empty_limit_file="/tmp/limit_file"
touch "${empty_limit_file}"
cleanup() {
if [[ -f "${empty_limit_file}" ]]; then
rm -rf "${empty_limit_file}"
fi
}
trap 'cleanup' EXIT
# https://github.com/ansible/ansible/issues/52152 # https://github.com/ansible/ansible/issues/52152
# Ensure that non-matching limit causes failure with rc 1 # Ensure that non-matching limit causes failure with rc 1
ansible-playbook -i ../../inventory --limit foo playbook.yml ansible-playbook -i ../../inventory --limit foo playbook.yml
@ -10,6 +21,9 @@ if [ "$?" != "1" ]; then
exit 1 exit 1
fi fi
# Ensure that non-matching limit causes failure with rc 1
ansible-playbook -i ../../inventory --limit @"${empty_limit_file}" playbook.yml
ansible-playbook -i ../../inventory "$@" strategy.yml ansible-playbook -i ../../inventory "$@" strategy.yml
ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS=always ansible-playbook -i ../../inventory "$@" strategy.yml ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS=always ansible-playbook -i ../../inventory "$@" strategy.yml
ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS=never ansible-playbook -i ../../inventory "$@" strategy.yml ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS=never ansible-playbook -i ../../inventory "$@" strategy.yml