sshkit.ex
sshkit.ex copied to clipboard
"sudo" support example?
I am using SSHKit to implement a tiny dev-ops checker (similar in spirit to ServerSpec/InSpec, but with more specific needs & also faster due to better parallelisation).
I believe the library does not support sudo explicitly. A sudo call via SSHKit.run
will result in an error similar to:
no match of right hand side value:
[{:ok, [stderr: "sudo", stderr: ": ",
stderr: "a terminal is required to read the password; either
use the -S option to read from standard input or configure
an askpass helper", stderr: "\n"], 1}]
My current state of research is this:
- pseudo TTY support could maybe help
- ServerSpec currently does this to manually enter the password
Did anyone already implement some code around that need? Happy to contribute back some documentation or code if I figure out how to achieve this!
Hey @thbar 👋
Thanks for reaching out! As far as I can remember, we did not yet run into a similar problem. Or better to say: we did not have a similar use case yet.
Still a super interesting application of sshkit! Can you give use more details of the pipeline and setup you're running, where this error occurs? It would help us to replicate the problem and better lay out the space for a potential fix / addition to sshkit 🤓
Just for the sake of completeness: the first thing that came to my mind when reading the issue title was the SSHKit.Context
module 🤔
But as said, I expect you're trying to do something slightly different. Curious for your code examples 👀
Hey @thbar. Expanding a bit on what @klappradla wrote:
SSHKit.run
uses sudo
under the hood if you specify a user in the SSHKit.Context
. For an example, you can take a look at the the "Usage" section in the README.md. Here's a trimmed-down version:
hosts = ["1.eg.io", {"2.eg.io", port: 2222}]
context =
SSHKit.context(hosts)
|> SSHKit.path("/var/www/phx")
|> SSHKit.user("deploy")
[{:ok, _, 0}, {:ok, _, 0}] = SSHKit.run(context, "yarn install")
This will run yarn install
as the deploy
user. If you adapt this a little, maybe your SSHKit.run
command does not even need to call sudo
? 🤿
Maybe that's all you need?
I may well be missing something in which case maybe you could give us a bit more detail on your usage scenario. We're happy to help out if we can. 😊
Cheers 🙂
@klappradla @pmeinhardt thanks for the notes!
Just a quick update: I will attempt to reproduce that in a Vagrant+VirtualBox script. If I can do this, I will share it here so we can improve the feature set.