Fix run_once by instantly tiny post_validate (#78492) (#80051)

Signed-off-by: tu1h <lihai.tu@daocloud.io>
pull/80377/head
tu1h 2 years ago committed by GitHub
parent 0e509ecf25
commit 043a0f3ee8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
---
bugfixes:
- "strategy plugins: get the correctly templated and validated run_once value on strategy linear (https://github.com/ansible/ansible/issues/78492)"

@ -35,6 +35,7 @@ from ansible import constants as C
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
@ -213,7 +214,10 @@ class StrategyModule(StrategyBase):
skip_rest = True
break
run_once = templar.template(task.run_once) or action and getattr(action, 'BYPASS_HOST_LOOP', False)
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)
if (task.any_errors_fatal or run_once) and not task.ignore_errors:
any_errors_fatal = True

@ -5,3 +5,5 @@ set -eux
ansible-playbook test_include_file_noop.yml -i inventory "$@"
ansible-playbook task_action_templating.yml -i inventory "$@"
ansible-playbook task_templated_run_once.yml -i inventory "$@"

@ -0,0 +1,20 @@
- hosts: testhost,testhost2
gather_facts: no
vars:
run_once_flag: false
tasks:
- debug:
msg: "I am {{ item }}"
run_once: "{{ run_once_flag }}"
register: reg1
loop:
- "{{ inventory_hostname }}"
- assert:
that:
- "reg1.results[0].msg == 'I am testhost'"
when: inventory_hostname == 'testhost'
- assert:
that:
- "reg1.results[0].msg == 'I am testhost2'"
when: inventory_hostname == 'testhost2'
Loading…
Cancel
Save