Created
January 16, 2013 19:25
-
-
Save krimdomu/4549997 to your computer and use it in GitHub Desktop.
Prompt for a password
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 Term::ReadKey; | |
user "root"; | |
# get the CLI parameters | |
my %args = Rex::Args->getopts; | |
# only ask for a password if the user don't want to list tasks. | |
if(! exists $args{T}) { | |
password read_password(); | |
} | |
task "test", "insttest-debian664", sub { | |
say run "hostname"; | |
}; | |
sub read_password { | |
print "Password please: "; | |
ReadMode "noecho"; # don't echo anything | |
my $password = <STDIN>; | |
chomp $password; | |
ReadMode 0; # reset terminal so it echo again | |
return $password; | |
} |
to change the sudo_password inside a task, you can do the following:
task "mytask", sub {
connection->server->{auth}->{sudo_password} = read_password();
sudo sub {
say run "id";
};
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for the sudo password one can do