Skip to content

Instantly share code, notes, and snippets.

@krimdomu
Created May 11, 2014 13:34
Show Gist options
  • Save krimdomu/b561cce86ef5c41e8b7c to your computer and use it in GitHub Desktop.
Save krimdomu/b561cce86ef5c41e8b7c to your computer and use it in GitHub Desktop.
different sudo authentication for servers
use Rex -feature => ['use_server_auth'];
use Term::ReadKey;
user "sudouser";
password "test";
group somegr => "10.211.55.28", "10.211.55.61";
# get the CLI parameters
my %args = Rex::Args->getopts;
if( !exists $args{T} ) {
map { $_->{auth}->{sudo_password} = read_password($_); }
Rex::Group->get_group('somegr');
}
task "test", group => 'somegr', sub {
sudo make { say run "id"; };
};
sub read_password {
my ($server) = @_;
print "Password please ($server): ";
ReadMode "noecho"; # don't echo anything
my $password = <STDIN>;
chomp $password;
ReadMode 0; # reset terminal so it echo again
print "\n"; # print a newline, for better output visibility
return $password;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment