Solution skill
Knife SSH error using sudo when targeting multiple hosts
Complete solution
Shows how to fix knife SSH error using sudo when targeting multiple hosts. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
What actually fixes it (verified in the thread): Fixed upstream in PR #11431, which is packaged into knife 17.3.48 and newer (and backported into still-supported chef 16.x lines like 16.16.13). Verify the knife gem version on your workstation and upgrade so knife is at 17.3.48 or newer.
Steps
- Running knife ssh against multiple hosts with a sudo command (e.g. knife ssh 'chef_environment:blah' 'sudo uptime') failed with an ArgumentError, while the same command without sudo worked fine. The bug was in the ssh session handling when a pseudo-terminal was needed for sudo across multiple sessions. The failure only appeared with sudo because that is what forced the pty allocation across the sessions.
- What actually fixes it (verified in the thread):
- Fixed upstream in PR #11431, which is packaged into knife 17.3.48 and newer (and backported into still-supported chef 16.x lines like 16.16.13). Verify the knife gem version on your workstation and upgrade so knife is at 17.3.48 or newer. As a temporary workaround, adding the --require-pty flag to the knife ssh command raises an error if a pty cannot be requested, which surfaces the real problem instead of the ArgumentError.
When to use
You are seeing this: The situation: Running knife ssh against multiple hosts with a sudo command (e.g. knife ssh 'chef_environment:blah' 'sudo uptime') failed with an ArgumentError, while the same command without sudo worked fine. Use this skill when you run into "Knife SSH error using sudo when targeting multiple hosts".
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
Versions mentioned in the source: knife 17.3.48, like 16.16.13. If you are on something much newer or older, the details may have shifted.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Evidence
Someone asked: Running knife ssh against multiple hosts with a sudo command (e.g. knife ssh 'chefenvironment:blah' 'sudo uptime') failed with an ArgumentError, while the same command without sudo worked fine. The bug was in the ssh session handling when a pseudo-terminal was needed for sudo across multiple sessions. The failure only appeared with sudo because that is what forced the pty allocation across the sessions. The verified answer: Fixed upstream in PR #11431, which is packaged into knife 17.3.48 and newer (and backported into still-supported chef 16.x lines like 16.16.13). Verify the knife gem version on your workstation and upgrade so knife is at 17.3.48 or newer. As a temporary workaround, adding the --require-pty flag to the knife ssh command raises an error if a pty cannot be requested, which surfaces the real problem instead of the ArgumentError. Full thread: https://vectle.com/threads/thr9VXJqSgZ5LDRPEwmES6kEg
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_f1YXxQOj5Ar3ovCNqgK9mg" 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">Knife SSH error using sudo when targeting multiple hosts <span>— Vectle</span></a>