New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No linear execution in handler after include_tasks with when condition #83019
Comments
Files identified in the description: None If these files are incorrect, please update the |
This appears to be another case of #82307 but unlike that issue #82170 isn't (yet) fixing it: #82307 (comment). |
Also, for next time, please note that we ask for output of |
Minimal reproducer: - hosts: h1,h2
gather_facts: false
tasks:
- command: echo
notify: handler
handlers:
- name: handler
include_tasks: 83019-handler.yml 83019-handler.yml: - include_tasks: 83019-handler-nested.yml
when: inventory_hostname == "h1"
- name: handler2
debug:
msg: handler2 83019-handler-nested.yml: - name: handler1
debug:
msg: handler1 Output:
|
Summary
We have a use-case where we want to restart a cluster, node by node with a handler. We use a when condition on an
include_tasks
to accomplish this. First we include the restart tasks for host 1, with a when condition. This is skipped for host 2. Afterwards we have anotherinclude_tasks
which is only applied to host 2.This workes on Ansible 6, but when upgrading to Ansible 8 this stopped working as expected. I was not able to find a change in the change log that specifically explains this behaviour, although I can see there are several changes made in this area.
I appears to me as a bug that a conditional (when)
include_tasks
behind a handler does not follow linear execution. What I see is that the host for which the condition is not true continues with the next task, while the host for which is condition is true, is executing the included tasks. If theinclude_tasks
with a when condition is not behind a handler but simply in the tasks of the role itself, then all included tasks are executed on the host that meets the when condition, while the other host waits and then they continue together afterwards. Which is as I'd expect.If I replace the
include_tasks
behind the handler with animport_tasks
which does a static (parse-time) import of the tasks. Then host 1 and 2 linearly run all imported tasks with the when condition on each task. This provides more or less the same outcome as with theinclude_task
in Ansible 6. But I'like to understand why theinclude_tasks
is no longer working as before.I've prepared a simple role to demonstrate the behavior with an include_task in the tasks of the role, and an import and include in the handler. In the expected result I've put the output of Ansible 6 in the actual result that of Ansible 8.7.0.
Issue Type
Bug Report
Component Name
core
Ansible Version
Configuration
OS / Environment
Ubuntu 20.04
Steps to Reproduce
tasks/main.yml
handlers/main.yml
handlers/restart_brokers.yml
handlers/restart_broker.yml
Expected Results
Actual Results
Code of Conduct
The text was updated successfully, but these errors were encountered: