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

Add a hostname in SSHKit.run's return tuple. #132

Open
seungjin opened this issue Sep 7, 2018 · 3 comments
Open

Add a hostname in SSHKit.run's return tuple. #132

seungjin opened this issue Sep 7, 2018 · 3 comments
Milestone

Comments

@seungjin
Copy link

seungjin commented Sep 7, 2018

It would be nice to add a hostname in SSHKit's return tuple.

Currently SSHKit.run returns {:ok, output, exit_code}. https://hexdocs.pm/sshkit/SSHKit.SSH.html#run/3
This is not going to be easy to see its output without hostname when we run SSHKit.run with :parallel.

Something like {:ok, hostname, output, exit_code} will be very helpful.

@pmeinhardt
Copy link
Contributor

Hi @seungjin,

if you have an SSHKit.Context struct context and the results of SSHKit.run/3, you could Enum.zip(context.hosts, results) together to tag each result with the corresponding host.

context = SSHKit.context(["h1.eg.io",])
results = SSHKit.run(context, "…")
Enum.zip(context.hosts, results)

However, we've had a similar request before and I can see why this might be useful 🤔

If we decide to add this, I would probably add the SSHKit.Host struct, not just its name (maybe this is what you've had in mind anyway):

["h1.eg.io", "h2.eg.io"]
|> SSHKit.context()
|> SSHKit.run("echo \"Hello World!\"")
# => [
#   {:ok, %SSHKit.host{name: "h1.eg.io", options: []}, [stdout: "Hello World!\n"], 0},
#   {:ok, %SSHKit.host{name: "h2.eg.io", options: []}, […], 0},
# ]

What do you think? 🙂


Also I'd like to hear a few more voices @tessi, @brienw, @holetse 👋🙂


PS: This'd be a "breaking change" requiring a major version bump.

@brienw
Copy link
Contributor

brienw commented Sep 10, 2018

+1 from me on adding this support.
I think this is something that we talked about changing in sshkit.ex last year some time when we were working on the output processing in Bootleg. I forget why we decided against it back then, but it would be great if the hostname (or some sort of identifier) was included in the output so we could explicitly know which host the output came from, instead of relying solely on the order of the elements in the output list. /cc-ing @rjanja for input as well, as he worked on the output logging/processing in Bootleg.

@rjanja
Copy link

rjanja commented Sep 10, 2018

We achieved similar parallel-run output w/ host names by passing a channel function to SSH.run/3. This could certainly be made simpler by returning a host struct, alias or index with each message from SSHKit, but that would indeed be a breaking change. Maybe it'd be possible to add (and document) an optional host-associating channel function that could be used for this purpose in lieu of introducing a breaking change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants