Last active
December 11, 2015 04:48
-
-
Save krimdomu/4547448 to your computer and use it in GitHub Desktop.
Using a jumphost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Rex -base; | |
user "foouser"; | |
task "uptime", "your-server", sub { | |
say run "uptime"; | |
}; | |
before uptime => sub { | |
my ($server, $server_ref) = @_; | |
# create local redirect to your-server on port 9999 | |
system("ssh -fN -L9999:$server:22 your-user\@your-jumphost"); | |
$$server_ref = "localhost:9999"; # rewrite server reference to localhost:9999 | |
}; | |
after uptime => sub { | |
my ($server) = @_; | |
my ($localhost, $port) = split(/:/, $server); | |
# get the redirecting process | |
my ($process) = grep { $_->{command} =~ m/^ssh \-fN \-L$port:$localhost/ } ps; | |
kill $process->{pid}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment