Skip to content

Commit

Permalink
Validate task attributes with first finalized attrs after individual …
Browse files Browse the repository at this point in the history
…loop results

ci_complete
  • Loading branch information
s-hertel committed Apr 11, 2023
1 parent bf4e016 commit 71a25e0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 5 additions & 0 deletions lib/ansible/executor/task_executor.py
Expand Up @@ -280,6 +280,7 @@ def _run_loop(self, items):
no_log = False
items_len = len(items)
results = []
post_validate = True
for item_index, item in enumerate(items):
task_vars['ansible_loop_var'] = loop_var

Expand Down Expand Up @@ -330,6 +331,9 @@ def _run_loop(self, items):
(self._play_context, tmp_play_context) = (tmp_play_context, self._play_context)
res = self._execute(variables=task_vars)
task_fields = self._task.dump_attrs()
if post_validate:
initial_attrs = task_fields
post_validate = False
(self._task, tmp_task) = (tmp_task, self._task)
(self._play_context, tmp_play_context) = (tmp_play_context, self._play_context)

Expand Down Expand Up @@ -391,6 +395,7 @@ def _run_loop(self, items):
if var in task_vars and var not in self._job_vars:
del task_vars[var]

self._task.from_attrs(initial_attrs)
self._task.no_log = no_log

return results
Expand Down
6 changes: 1 addition & 5 deletions lib/ansible/plugins/strategy/linear.py
Expand Up @@ -35,7 +35,6 @@
from ansible.errors import AnsibleError, AnsibleAssertionError, AnsibleParserError
from ansible.executor.play_iterator import IteratingStates, FailedStates
from ansible.module_utils._text import to_text
from ansible.module_utils.parsing.convert_bool import boolean
from ansible.playbook.handler import Handler
from ansible.playbook.included_file import IncludedFile
from ansible.playbook.task import Task
Expand Down Expand Up @@ -214,10 +213,7 @@ def run(self, iterator, play_context):
skip_rest = True
break

if templar.is_template(task.run_once):
setattr(task, 'run_once', boolean(templar.template(task.run_once), strict=True))

run_once = task.run_once or action and getattr(action, 'BYPASS_HOST_LOOP', False)
run_once = templar.template(task.run_once) or action and getattr(action, 'BYPASS_HOST_LOOP', False)

if (task.any_errors_fatal or run_once) and not task.ignore_errors:
any_errors_fatal = True
Expand Down

0 comments on commit 71a25e0

Please sign in to comment.