Skip to content
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

[stable-2.16] handlers: fix executing in lockstep using linear (#83030) #83073

Merged
merged 1 commit into from May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/82307-handlers-lockstep-linear-fix.yml
@@ -0,0 +1,2 @@
bugfixes:
- Fix handlers not being executed in lockstep using the linear strategy in some cases (https://github.com/ansible/ansible/issues/82307)
2 changes: 1 addition & 1 deletion lib/ansible/executor/play_iterator.py
Expand Up @@ -429,13 +429,13 @@ def _get_next_task_from_state(self, state, host):
# might be there from previous flush
state.handlers = self.handlers[:]
state.update_handlers = False
state.cur_handlers_task = 0

while True:
try:
task = state.handlers[state.cur_handlers_task]
except IndexError:
task = None
state.cur_handlers_task = 0
state.run_state = state.pre_flushing_run_state
state.update_handlers = True
break
Expand Down
25 changes: 25 additions & 0 deletions test/integration/targets/handlers/handlers_lockstep_82307.yml
@@ -0,0 +1,25 @@
- hosts: A,B
gather_facts: false
tasks:
- block:
- command: echo
notify:
- handler1
- handler2

- fail:
when: inventory_hostname == "B"

- meta: flush_handlers
always:
- name: always
debug:
msg: always
handlers:
- name: handler1
debug:
msg: handler1

- name: handler2
debug:
msg: handler2
3 changes: 3 additions & 0 deletions test/integration/targets/handlers/runme.sh
Expand Up @@ -208,3 +208,6 @@ ansible-playbook 82241.yml -i inventory.handlers "$@" 2>&1 | tee out.txt
ansible-playbook nested_flush_handlers_failure_force.yml -i inventory.handlers "$@" 2>&1 | tee out.txt
[ "$(grep out.txt -ce 'flush_handlers_rescued')" = "1" ]
[ "$(grep out.txt -ce 'flush_handlers_always')" = "2" ]

ansible-playbook handlers_lockstep_82307.yml -i inventory.handlers "$@" 2>&1 | tee out.txt
[ "$(grep out.txt -ce 'TASK \[handler2\]')" = "0" ]