diff options
author | James Cammarata <jimi@sngx.net> | 2017-05-18 03:47:44 -0500 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2017-05-18 09:29:53 -0500 |
commit | 3afaf5baf299015793bff604c0c713e75adb80d7 (patch) | |
tree | 73b68f12dde486651ddef71039411937012d7553 | |
parent | 400991f63557564eef3308b4b4810b8f0927281f (diff) | |
download | ansible-issue_24650_template_loop_control.tar.gz |
Properly template the loop_control field for tasksissue_24650_template_loop_control
The loop control field was being used before being post-validated. Also,
the fields were not marked as always_post_validate, so they were not being
templated even during the regular post validation step of the task.
Fixes #24650
-rw-r--r-- | lib/ansible/executor/task_executor.py | 19 | ||||
-rw-r--r-- | lib/ansible/playbook/loop_control.py | 6 |
2 files changed, 14 insertions, 11 deletions
diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 389fa5542d..2514cce030 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -253,13 +253,9 @@ class TaskExecutor: task_vars = self._job_vars loop_var = 'item' - label = None - loop_pause = 0 if self._task.loop_control: # the value may be 'None', so we still need to default it back to 'item' loop_var = self._task.loop_control.loop_var or 'item' - label = self._task.loop_control.label or ('{{' + loop_var + '}}') - loop_pause = self._task.loop_control.pause or 0 if loop_var in task_vars: display.warning(u"The loop variable '%s' is already in use. " @@ -271,6 +267,16 @@ class TaskExecutor: for item in items: task_vars[loop_var] = item + templar = Templar(loader=self._loader, shared_loader_obj=self._shared_loader_obj, variables=task_vars) + if self._task.loop_control: + loop_control = self._task.loop_control.copy() + loop_control.post_validate(templar) + label = loop_control.label or templar.template('{{' + loop_var + '}}') + loop_pause = loop_control.pause or 0 + else: + label = templar.template('{{' + loop_var + '}}') + loop_pause = 0 + # pause between loop iterations if loop_pause and ran_once: time.sleep(loop_pause) @@ -297,10 +303,7 @@ class TaskExecutor: # to the list of results res[loop_var] = item res['_ansible_item_result'] = True - - if label is not None: - templar = Templar(loader=self._loader, shared_loader_obj=self._shared_loader_obj, variables=self._job_vars) - res['_ansible_item_label'] = templar.template(label) + res['_ansible_item_label'] = label self._rslt_q.put( TaskResult( diff --git a/lib/ansible/playbook/loop_control.py b/lib/ansible/playbook/loop_control.py index cd7a9c7b59..fde74068ef 100644 --- a/lib/ansible/playbook/loop_control.py +++ b/lib/ansible/playbook/loop_control.py @@ -29,9 +29,9 @@ from ansible.playbook.base import Base class LoopControl(Base): - _loop_var = FieldAttribute(isa='str') - _label = FieldAttribute(isa='str') - _pause = FieldAttribute(isa='int') + _loop_var = FieldAttribute(isa='str', always_post_validate=True) + _label = FieldAttribute(isa='str', always_post_validate=True) + _pause = FieldAttribute(isa='float', always_post_validate=True) def __init__(self): super(LoopControl, self).__init__() |