mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Ensure loop with delegate_to can short circuit the same as without delegate_to. Fixes #45189 (#45231)
This commit is contained in:
parent
9a76441c02
commit
2ac647def8
3 changed files with 29 additions and 1 deletions
4
changelogs/fragments/loop_undefined_delegate_to.yaml
Normal file
4
changelogs/fragments/loop_undefined_delegate_to.yaml
Normal file
|
@ -0,0 +1,4 @@
|
|||
bugfixes:
|
||||
- loop - Ensure that a loop with a when condition that evaluates to false and delegate_to, will short circuit if the
|
||||
loop references an undefined variable. This matches the behavior in the same scenario without delegate_to
|
||||
(https://github.com/ansible/ansible/issues/45189)
|
|
@ -512,7 +512,12 @@ class VariableManager:
|
|||
else:
|
||||
raise AnsibleError("Failed to find the lookup named '%s' in the available lookup plugins" % task.loop_with)
|
||||
elif task.loop is not None:
|
||||
items = templar.template(task.loop)
|
||||
try:
|
||||
items = templar.template(task.loop)
|
||||
except AnsibleUndefinedVariable:
|
||||
# This task will be skipped later due to this, so we just setup
|
||||
# a dummy array for the later code so it doesn't fail
|
||||
items = [None]
|
||||
else:
|
||||
has_loop = False
|
||||
items = [None]
|
||||
|
|
|
@ -233,3 +233,22 @@
|
|||
- assert:
|
||||
that:
|
||||
- ansible_search_path == loop_search_path.results.0.item
|
||||
|
||||
# https://github.com/ansible/ansible/issues/45189
|
||||
- name: with_X conditional delegate_to shortcircuit on templating error
|
||||
debug:
|
||||
msg: "loop"
|
||||
when: false
|
||||
delegate_to: localhost
|
||||
with_list: "{{ fake_var }}"
|
||||
register: result
|
||||
failed_when: result is not skipped
|
||||
|
||||
- name: loop conditional delegate_to shortcircuit on templating error
|
||||
debug:
|
||||
msg: "loop"
|
||||
when: false
|
||||
delegate_to: localhost
|
||||
loop: "{{ fake_var }}"
|
||||
register: result
|
||||
failed_when: result is not skipped
|
||||
|
|
Loading…
Reference in a new issue