Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inventory: Handle IndexError while parsing limit file #59776

Merged
merged 1 commit into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/limit_file_parsing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- Handle IndexError while parsing empty limit file (https://github.com/ansible/ansible/issues/59695).
5 changes: 4 additions & 1 deletion lib/ansible/inventory/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ def order_patterns(patterns):
pattern_intersection = []
pattern_exclude = []
for p in patterns:
if not p:
continue

if p[0] == "!":
pattern_exclude.append(p)
elif p[0] == "&":
pattern_intersection.append(p)
elif p:
else:
pattern_regular.append(p)

# if no regular pattern was given, hence only exclude and/or intersection
Expand Down
14 changes: 14 additions & 0 deletions test/integration/targets/inventory/runme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

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
# Ensure that non-matching limit causes failure with rc 1
ansible-playbook -i ../../inventory --limit foo playbook.yml
Expand All @@ -10,6 +21,9 @@ if [ "$?" != "1" ]; then
exit 1
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_TRANSFORM_INVALID_GROUP_CHARS=always ansible-playbook -i ../../inventory "$@" strategy.yml
ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS=never ansible-playbook -i ../../inventory "$@" strategy.yml