When using meta: reset_connection (directly or via a handler triggered by meta: flush_handlers), the playbook fails with:
[ERROR]: A worker was found in a dead state
Use Case
Common pattern for allowing a user to access Docker after being added to the docker group on first run (see Jeff Geerling’s blog):
- name: Add user to docker group
ansible.builtin.user:
name: "{{ ansible_user }}"
groups: docker
append: true
notify: Reset connection
- name: Flush handlers
ansible.builtin.meta: flush_handlers
- name: Deploy container # Fails: worker dead
community.docker.docker_compose_v2:
project_src: /opt/coredns
state: present
handlers:
- name: Reset connection
ansible.builtin.meta: reset_connection
Environment
- Controller: macOS (ansible-playbook run locally)
- Target: Linux hosts (SSH)
- Ansible version:
ansible [core 2.19.2]
config file = None
configured module search path = ['/Users/gowgopal/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /opt/homebrew/Cellar/ansible/12.0.0/libexec/lib/python3.13/site-packages/ansible
ansible collection location = /Users/gowgopal/.ansible/collections:/usr/share/ansible/collections
executable location = /opt/homebrew/bin/ansible
python version = 3.13.7 (main, Aug 14 2025, 11:12:11) [Clang 17.0.0 (clang-1700.3.19.1)] (/opt/homebrew/Cellar/ansible/12.0.0/libexec/bin/python)
jinja version = 3.1.6
pyyaml version = 6.0.2 (with libyaml v0.2.5)
Expected Behavior
Connection resets cleanly; subsequent tasks run with a fresh SSH session that has the new group membership.
Actual Behavior
Worker process dies; playbook fails with “A worker was found in a dead state” on the next task.
Workaround
Avoid reset_connection and use sg to run Docker commands with the group active:
- name: Start containers
ansible.builtin.command:
cmd: sg docker -c "docker compose up -d --pull always"
args:
chdir: /opt/coredns
Related Issues / PRs
- ansible#50306 – Meta module: reset_connection is always failing (handler returns “connection closed” as failure)
- ansible#73708 – Fix: reset_connection to use same parameters for socket check (SSH plugin migration)
- ansible#32554 – “A worker was found in a dead state”
- ansible#79757 – Worker dead state affecting operator
- ansible#68341 – SSH connection reset and controlpath