Immutable solution version
ansible.builtin.raw -- Successfully completes however play ends with UNREACHABLE error
Complete solution
Shows how to fix ansible.builtin.raw -- Successfully completes however play ends with UNREACHABLE error. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Or switch those tasks to paramiko instead of ssh with ansible\_connection: paramiko on the host.
Steps
- Ansible treats rc 255 as an SSH protocol error, so a raw task can succeed and still end the play as UNREACHABLE. The workaround: wrap your command in a shell one-liner or script that translates exit code 255 into something else, e.g.
mycommand; rc=$?; [ $rc -eq 255 ] && exit 1 || exit $rc. Or switch those tasks to paramiko instead of ssh withansible_connection: paramikoon the host. Either way, stop 255 from leaking through SSH and the false UNREACHABLE goes away. - Source: https://github.com/ansible/ansible/issues/80335 (Ansible)
When to use
You are seeing this: Ansible treats rc 255 as an SSH protocol error, so a raw task can succeed and still end the play as UNREACHABLE. Use this skill when you run into "ansible.builtin.raw -- Successfully completes however play ends with UNREACHABLE error".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Sources
- https://github.com/ansible/ansible/issues/80335
Evidence
In gh:ansible/ansible#80335, the issue was: ### Summary I have a small playbook which installs a BigFix client on to an AIX LPAR (VM) where python is NOT installed. As a result I use the ansible.builtin.raw module. The play "works" in that the BigFix agent is successfully installed (so a valid SSH connections must be established) however the task ends in "failure". I can "overcome" the failure(s) by adding the following to the tasks which, although not ideal, does seem to work. ignoreerrors: true ignoreunreachable: true ### Issue Type Bug Report ### Component Name raw ### Ansible Version ``console $ ansible --version ansible 2.9.25 c. The verified answer: Ansible treats rc 255 as an SSH protocol error, so a raw task can succeed and still end the play as UNREACHABLE. The workaround: wrap your command in a shell one-liner or script that translates exit code 255 into something else, e.g. mycommand; rc=$?; [ $rc -eq 255 ] && exit 1 || exit $rc`.. Issue URL: https://github.com/ansible/ansible/issues/80335
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_4QoMhn0ksYHZh2K7esP95Q" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">ansible.builtin.raw -- Successfully completes however play ends with UNREACHABLE error <span>— Vectle</span></a>