mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fixing bugs with {changed,failed}_when and until with registered vars
* Saving of the registered variable was occuring after the tests for changed/failed_when. * Each of the above fields and until were being post_validated too early, so variables which were not defined at that time were causing task failures. Fixes #13591
This commit is contained in:
parent
1debc2da44
commit
a3dcb910b8
2 changed files with 26 additions and 6 deletions
|
@ -387,7 +387,6 @@ class TaskExecutor:
|
||||||
|
|
||||||
# make a copy of the job vars here, in case we need to update them
|
# make a copy of the job vars here, in case we need to update them
|
||||||
# with the registered variable value later on when testing conditions
|
# with the registered variable value later on when testing conditions
|
||||||
#vars_copy = variables.copy()
|
|
||||||
vars_copy = variables.copy()
|
vars_copy = variables.copy()
|
||||||
|
|
||||||
display.debug("starting attempt loop")
|
display.debug("starting attempt loop")
|
||||||
|
@ -404,6 +403,11 @@ class TaskExecutor:
|
||||||
return dict(unreachable=True, msg=to_unicode(e))
|
return dict(unreachable=True, msg=to_unicode(e))
|
||||||
display.debug("handler run complete")
|
display.debug("handler run complete")
|
||||||
|
|
||||||
|
# update the local copy of vars with the registered value, if specified,
|
||||||
|
# or any facts which may have been generated by the module execution
|
||||||
|
if self._task.register:
|
||||||
|
vars_copy[self._task.register] = result
|
||||||
|
|
||||||
if self._task.async > 0:
|
if self._task.async > 0:
|
||||||
# the async_wrapper module returns dumped JSON via its stdout
|
# the async_wrapper module returns dumped JSON via its stdout
|
||||||
# response, so we parse it here and replace the result
|
# response, so we parse it here and replace the result
|
||||||
|
@ -433,11 +437,6 @@ class TaskExecutor:
|
||||||
return failed_when_result
|
return failed_when_result
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# update the local copy of vars with the registered value, if specified,
|
|
||||||
# or any facts which may have been generated by the module execution
|
|
||||||
if self._task.register:
|
|
||||||
vars_copy[self._task.register] = result
|
|
||||||
|
|
||||||
if 'ansible_facts' in result:
|
if 'ansible_facts' in result:
|
||||||
vars_copy.update(result['ansible_facts'])
|
vars_copy.update(result['ansible_facts'])
|
||||||
|
|
||||||
|
|
|
@ -260,6 +260,27 @@ class Task(Base, Conditional, Taggable, Become):
|
||||||
break
|
break
|
||||||
return templar.template(value, convert_bare=True)
|
return templar.template(value, convert_bare=True)
|
||||||
|
|
||||||
|
def _post_validate_changed_when(self, attr, value, templar):
|
||||||
|
'''
|
||||||
|
changed_when is evaluated after the execution of the task is complete,
|
||||||
|
and should not be templated during the regular post_validate step.
|
||||||
|
'''
|
||||||
|
return value
|
||||||
|
|
||||||
|
def _post_validate_failed_when(self, attr, value, templar):
|
||||||
|
'''
|
||||||
|
failed_when is evaluated after the execution of the task is complete,
|
||||||
|
and should not be templated during the regular post_validate step.
|
||||||
|
'''
|
||||||
|
return value
|
||||||
|
|
||||||
|
def _post_validate_until(self, attr, value, templar):
|
||||||
|
'''
|
||||||
|
until is evaluated after the execution of the task is complete,
|
||||||
|
and should not be templated during the regular post_validate step.
|
||||||
|
'''
|
||||||
|
return value
|
||||||
|
|
||||||
def get_vars(self):
|
def get_vars(self):
|
||||||
all_vars = dict()
|
all_vars = dict()
|
||||||
if self._block:
|
if self._block:
|
||||||
|
|
Loading…
Reference in a new issue