Brian Coca 2 weeks ago committed by GitHub
commit 730e282885
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -379,6 +379,17 @@ class TaskExecutor:
self._final_q.send_callback('v2_runner_item_on_ok', tr)
results.append(res)
# break loop if until conditions are met
if self._task.loop_control and self._task.loop_control.until is not None:
cond = Conditional(loader=self._loader)
cond.when = self._task.loop_control.get_validated_value('until', self._task.loop_control._until, self._task.loop_control.until, templar)
if cond.evaluate_conditional(templar, task_vars):
# delete loop vars before exiting loop
del task_vars[loop_var]
break
# done with loop var, remove for next iteration
del task_vars[loop_var]
# clear 'connection related' plugin variables for next iteration

@ -29,6 +29,7 @@ class LoopControl(FieldAttributeBase):
pause = NonInheritableFieldAttribute(isa='float', default=0, always_post_validate=True)
extended = NonInheritableFieldAttribute(isa='bool', always_post_validate=True)
extended_allitems = NonInheritableFieldAttribute(isa='bool', default=True, always_post_validate=True)
until = NonInheritableFieldAttribute(isa='list', default=list)
def __init__(self):
super(LoopControl, self).__init__()
@ -37,3 +38,10 @@ class LoopControl(FieldAttributeBase):
def load(data, variable_manager=None, loader=None):
t = LoopControl()
return t.load_data(data, variable_manager=variable_manager, loader=loader)
def _post_validate_until(self, attr, value, templar):
'''
until is evaluated after the execution of the loop is complete,
and should not be templated during the regular post_validate step.
'''
return value

@ -10,3 +10,5 @@ bar_label'
[ "$(ansible-playbook label.yml "$@" |grep 'item='|sed -e 's/^.*(item=looped_var \(.*\)).*$/\1/')" == "${MATCH}" ]
ansible-playbook extended.yml "$@"
ansible-playbook until.yml "$@"

@ -0,0 +1,17 @@
- hosts: localhost
gather_facts: false
tasks:
- debug: var=item
changed_when: false
loop:
- 1
- 2
- 3
- 4
loop_control:
until: item >= 2
register: untiltest
- assert:
that:
- untiltest['results']|length == 2
Loading…
Cancel
Save