view release on metacpan or search on metacpan
 - Don't hardcode LibXML dependency - Jan Gehring
 - workaround for wrong behaviour with -f and windows symlinks - Jan
   Gehring
 - it seems that the channel sometimes doesn't get closed in time. so we
   need an option to force close it after command run. - Jan Gehring
 - fixed reporting for named resource - Jan Gehring
 - pass cli parameters to tasks for pre 1.4 feature flags. fix #1039 - Jan
   Gehring
 - fixed old style Rex::Args->get when called from outside a task - Jan
   Gehring
 - Fix for #1054 - get_private_key() to check the private key file - Tamas
   Molnar
 - Fix for #1052 - mask sudo_password in debug log - Tamas Molnar
 - exit rex with an exitcode of 1 if some tests failed. fix #989 - Jan
   Gehring
 - show how to assign a user with a non-default shell - Andrew Solomon
 - Fix example code (fix #1034) - Ferenc Erki
 - Update example tasknames - Ferenc Erki
 - Add possible root cause to authentication error message (fix #671) -
   Ferenc Erki
 - Correct message for authentication problems - Ferenc Erki
   - Jan
 - start of unit-test for Rex::Commands::DB - Volker Kroll (vkroll)
 - better fix for #521, don't print all servers by rex -T. Also fixed group
   authentication. - Jan
 - patch from twitter/@tekcurmudgeon to allow setting of gpgkey for a
   repository - Jan
 - fixed late group lookup - #521 - Jan
 - if the evaluation of the Rexfile was without syntax errors, but don't
   return a true value, try to evaluate it manually. so is is not needed to
   return a true value at the end. - fix for #513 - Jan
 - fixed path resolution for private_key and public_key when used a ~
   (tilde) sign. #517 - Jan
 - fix rsync with port definition - #520 - Jan
 - added parse_templates option to sync_up function, so that template
   parsing can be prevented - #519 - Jan
 - Rex::FS::File accepts filenames now - reneeb
 - Add initial version of changelog generator - Ferenc Erki
0.18 2011-09-01 Jan Gehring <jan.gehring, gmail.com>
 - added network support for Solaris, NetBSD, FreeBSD and OpenBSD
 - added is_solaris, is_bsd and is_linux function
See all the available commands in L<Rex::Commands>.
=head3 Simple authentication
 user 'bruce';
 password 'batman';
 pass_auth;
=head3 Key authentication
 private_key '/path/to/your/private/key.file';
 public_key '/path/to/your/public/key.file';
 key_auth;
=head3 Define logging
 logging to_file   => 'rex.log';
 logging to_syslog => 'local0';
=head3 Group your servers
Use this function to create a connection if you use Rex as a library.
 use Rex;
 use Rex::Commands::Run;
 use Rex::Commands::Fs;
 Rex::connect(
   server    => "remotehost",
   user      => "root",
   password   => "f00b4r",
   private_key => "/path/to/private/key/file",
   public_key  => "/path/to/public/key/file",
 );
 if(is_file("/foo/bar")) {
   print "Do something...\n";
 }
 my $output = run("uptime");
=cut
lib/Rex/Box/Base.pm view on Meta::CPAN
  my $that  = shift;
  my $proto = ref($that) || $that;
  my $self  = {@_};
  bless( $self, $proto );
  # default auth for rex boxes
  $self->{__auth} = {
    user        => Rex::Config->get_user(),
    password    => Rex::Config->get_password(),
    private_key => Rex::Config->get_private_key(),
    public_key  => Rex::Config->get_public_key(),
  };
  # for box this is needed, because we have changing ips
  Rex::Config->set_openssh_opt(
    StrictHostKeyChecking => "no",
    UserKnownHostsFile    => "/dev/null",
    LogLevel              => "QUIET"
  );
lib/Rex/Box/Base.pm view on Meta::CPAN
  $self->{force} = $force;
}
=head2 auth(%option)
Configure the authentication to the VM.
 $box->auth(
   user => $user,
   password => $password,
   private_key => $private_key,
   public_key => $public_key,
 );
=cut
sub auth {
  my ( $self, %auth ) = @_;
  if (%auth) {
    $self->{__auth} = \%auth;
  }
lib/Rex/CLI.pm view on Meta::CPAN
        $pass_auth = 1;
      }
      for my $task ( Rex::TaskList->create()->get_tasks ) {
        Rex::TaskList->create()->get_task($task)->set_password( $opts{'p'} );
      }
    }
    if ( $opts{'P'} ) {
      Rex::Commands::private_key( $opts{'P'} );
      for my $task ( Rex::TaskList->create()->get_tasks ) {
        Rex::TaskList->create()
          ->get_task($task)
          ->set_auth( "private_key", $opts{'P'} );
      }
    }
    if ( $opts{'K'} ) {
      Rex::Commands::public_key( $opts{'K'} );
      for my $task ( Rex::TaskList->create()->get_tasks ) {
        Rex::TaskList->create()
          ->get_task($task)
          ->set_auth( "public_key", $opts{'K'} );
lib/Rex/CLI.pm view on Meta::CPAN
    if ( $opts{'p'} ) {
      Rex::Commands::password( $opts{'p'} );
      unless ( $opts{'P'} ) {
        $pass_auth = 1;
      }
    }
    if ( $opts{'P'} ) {
      Rex::Commands::private_key( $opts{'P'} );
    }
    if ( $opts{'K'} ) {
      Rex::Commands::public_key( $opts{'K'} );
    }
    if ($pass_auth) {
      pass_auth;
    }
lib/Rex/Commands.pm view on Meta::CPAN
use Rex::RunList;
use Symbol;
use Carp;
use vars
  qw(@EXPORT $current_desc $global_no_ssh $environments $dont_register_tasks $profiler %auth_late);
use base qw(Rex::Exporter);
@EXPORT = qw(task desc group
  user password port sudo_password public_key private_key pass_auth key_auth krb5_auth no_ssh
  get_random batch timeout max_connect_retries parallelism proxy_command
  do_task run_task run_batch needs
  exit
  evaluate_hostname
  logging
  include
  say
  environment
  LOCAL
  path
lib/Rex/Commands.pm view on Meta::CPAN
 group frontends => "web[01..10]";
 group backends => "be[01..05]";
 auth for => "frontends" =>
            user => "root",
            password => "foobar";
 auth for => "backends" =>
            user => "admin",
            private_key => "/path/to/id_rsa",
            public_key => "/path/to/id_rsa.pub",
            sudo => TRUE;
 # auth for tasks
 task "prepare", group => ["frontends", "backends"], sub {
   # do something
 };
 auth for => "prepare" =>
lib/Rex/Commands.pm view on Meta::CPAN
 auth for => qr/step/ =>
   user     => $user,
   password => $password;
 # fallback auth
 auth fallback => {
   user        => "fallback_user1",
   password    => "fallback_pw1",
   public_key  => "",
   private_key => "",
 }, {
   user        => "fallback_user2",
   password    => "fallback_pw2",
   public_key  => "keys/public.key",
   private_key => "keys/private.key",
   sudo        => TRUE,
 };
=cut
sub auth {
  if ( !ref $_[0] && $_[0] eq "fallback" ) {
    # set fallback authentication
lib/Rex/Commands.pm view on Meta::CPAN
=head2 public_key($key)
Set the public key.
=cut
sub public_key {
  Rex::Config->set_public_key(@_);
}
=head2 private_key($key)
Set the private key.
=cut
sub private_key {
  Rex::Config->set_private_key(@_);
}
=head2 pass_auth
If you want to use password authentication, then you need to call I<pass_auth>.
 user "root";
 password "root";
 pass_auth;
lib/Rex/Commands.pm view on Meta::CPAN
sub pass_auth {
  if (wantarray) { return "pass"; }
  Rex::Config->set_password_auth(1);
}
=head2 key_auth
If you want to use pubkey authentication, then you need to call I<key_auth>.
 user "bob";
 private_key "/home/bob/.ssh/id_rsa"; # passphrase-less key
 public_key "/home/bob/.ssh/id_rsa.pub";
 key_auth;
=cut
sub key_auth {
  if (wantarray) { return "key"; }
  Rex::Config->set_key_auth(1);
}
lib/Rex/Commands/Cloud.pm view on Meta::CPAN
=cut
sub cloud_image_list {
  return cloud_object()->list_images();
}
=head2 cloud_upload_key
Upload public SSH key to cloud provider
 private_key '~/.ssh/mykey
 public_key  '~/.ssh/mykey.pub';
 task "cloudprovider", sub {
   cloud_upload_key;
   cloud_instance create => {
     ...
   };
 };
lib/Rex/Commands/Rsync.pm view on Meta::CPAN
  }
  $cmd = join( " ", @rsync_cmd );
  if ( !$local_connection ) {
    my $pass           = $auth->{password};
    my @expect_options = ();
    my $auth_type = $auth->{auth_type};
    if ( $auth_type eq "try" ) {
      if ( $server->get_private_key && -f $server->get_private_key ) {
        $auth_type = "key";
      }
      else {
        $auth_type = "pass";
      }
    }
    if ( $auth_type eq "pass" ) {
      $cmd = sprintf( $cmd,
        "ssh -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -p $port",
lib/Rex/Commands/Rsync.pm view on Meta::CPAN
            die;
          }
        ],
      );
    }
    else {
      if ( $auth_type eq "key" ) {
        $cmd = sprintf( $cmd,
              'ssh -i '
            . $server->get_private_key
            . " -o StrictHostKeyChecking=no -p $port" );
      }
      else {
        $cmd = sprintf( $cmd, 'ssh -o StrictHostKeyChecking=no -p ' . "$port" );
      }
      push(
        @expect_options,
        [
          qr{Are you sure you want to continue connecting},
          sub {
lib/Rex/Config.pm view on Meta::CPAN
use YAML;
use Data::Dumper;
use Rex::Require;
use Symbol;
our (
  $user,                        $password,
  $port,                        $timeout,
  $max_connect_fails,           $password_auth,
  $key_auth,                    $krb5_auth,
  $public_key,                  $private_key,
  $parallelism,                 $log_filename,
  $log_facility,                $sudo_password,
  $ca_file,                     $ca_cert,
  $ca_key,                      $path,
  $no_path_cleanup,             $set_param,
  $environment,                 $connection_type,
  $distributor,                 $template_function,
  $SET_HANDLER,                 $HOME_CONFIG,
  $HOME_CONFIG_YAML,            %SSH_CONFIG_FOR,
  $sudo_without_locales,        $sudo_without_sh,
lib/Rex/Config.pm view on Meta::CPAN
sub get_public_key {
  if ( exists $ENV{REX_PUBLIC_KEY} ) { return $ENV{REX_PUBLIC_KEY}; }
  if ($public_key) {
    return $public_key;
  }
  return;
}
=head2 set_private_key
=head2 get_private_key
Sets and gets the value of the C<$private_key> configuration variable.
This controls which L<private key|Rex::Commands#private_key> Rex should use with L<Rex::Commands::Rsync> or when using L<Net::SSH2> for connections.
Default is C<undef>.
=cut
sub set_private_key {
  my $class = shift;
  $private_key = shift;
}
sub has_private_key {
  return get_private_key();
}
sub get_private_key {
  if ( exists $ENV{REX_PRIVATE_KEY} ) { return $ENV{REX_PRIVATE_KEY}; }
  if ($private_key) {
    return $private_key;
  }
  return;
}
=head2 set_parallelism
=head2 get_parallelism
Sets and gets the value of the C<$parallelism> configuration variable.
lib/Rex/Config.pm view on Meta::CPAN
      return $param->{server} . $1;
    }
    else {
      return $SSH_CONFIG_FOR{ $param->{server} }->{hostname};
    }
  }
  return 0;
}
sub get_ssh_config_private_key {
  my $class = shift;
  my $param = {@_};
  if ( exists $param->{server}
    && exists $SSH_CONFIG_FOR{ $param->{server} }
    && exists $SSH_CONFIG_FOR{ $param->{server} }->{identityfile} )
  {
    my $file     = $SSH_CONFIG_FOR{ $param->{server} }->{identityfile};
    my $home_dir = _home_dir();
lib/Rex/Config.pm view on Meta::CPAN
        ${$ref_to_key_scalar} = $param->{$key};
      }
    }
  );
}
_register_set_handlers();
sub _register_set_handlers {
  my @set_handler =
    qw/user password private_key public_key -keyauth -passwordauth -passauth
    parallelism sudo_password connection ca cert key distributor
    template_function port waitpid_blocking_sleep_time/;
  for my $hndl (@set_handler) {
    __PACKAGE__->register_set_handler(
      $hndl => sub {
        my ($val) = @_;
        if ( $hndl =~ m/^\-/ ) {
          $hndl = substr( $hndl, 1 );
        }
        if ( $hndl eq "keyauth" ) { $hndl = "key_auth"; $val = 1; }
lib/Rex/Group/Entry/Server.pm view on Meta::CPAN
  if ( $self->{port} ) {
    $self->{auth}->{port} = $self->{port};
    delete $self->{port};
  }
  if ( $self->{public_key} ) {
    $self->{auth}->{public_key} = $self->{public_key};
    delete $self->{public_key};
  }
  if ( $self->{private_key} ) {
    $self->{auth}->{private_key} = $self->{private_key};
    delete $self->{private_key};
  }
  if ( $self->{sudo} ) {
    $self->{auth}->{sudo} = $self->{sudo};
    delete $self->{sudo};
  }
  if ( $self->{sudo_password} ) {
    $self->{auth}->{sudo_password} = $self->{sudo_password};
    delete $self->{sudo_password};
lib/Rex/Group/Entry/Server.pm view on Meta::CPAN
    Rex::Logger::debug(
      "Rex::Group::Entry::Server (public_key): returning $key");
    return $key;
  }
  Rex::Logger::debug( "Rex::Group::Entry::Server (public_key): returning "
      . ( Rex::Config->get_public_key || "" ) );
  return Rex::Config->get_public_key;
}
sub get_private_key {
  my ($self) = @_;
  if ( exists $self->{auth}->{private_key} && -f $self->{auth}->{private_key} )
  {
    Rex::Logger::debug( "Rex::Group::Entry::Server (private_key): returning "
        . $self->{auth}->{private_key} );
    return $self->{auth}->{private_key};
  }
  if (!Rex::Config->has_private_key
    && Rex::Config->get_ssh_config_private_key( server => $self->to_s ) )
  {
    Rex::Logger::debug("Checking for a private key in .ssh/config");
    my $key = Rex::Config->get_ssh_config_private_key( server => $self->to_s );
    Rex::Logger::debug(
      "Rex::Group::Entry::Server (private_key): returning " . $key );
    return $key;
  }
  Rex::Logger::debug( "Rex::Group::Entry::Server (private_key): returning "
      . ( Rex::Config->get_private_key || "" ) );
  return Rex::Config->get_private_key;
}
sub get_auth_type {
  my ($self) = @_;
  if ( exists $self->{auth}->{auth_type} && $self->{auth}->{auth_type} ) {
    return $self->{auth}->{auth_type};
  }
  if ( exists $self->{auth}->{public_key}
    && -f $self->{auth}->{public_key}
    && exists $self->{auth}->{private_key}
    && -f $self->{auth}->{private_key} )
  {
    return "try";
  }
  elsif ( exists $self->{auth}->{user}
    && $self->{auth}->{user}
    && exists $self->{auth}->{password}
    && $self->{auth}->{password} ne "" )
  {
    return "try";
  }
lib/Rex/Group/Entry/Server.pm view on Meta::CPAN
  }
  Rex::Config->get_sudo_password;
}
sub merge_auth {
  my ( $self, $other_auth ) = @_;
  my %new_auth;
  my @keys =
    qw/user password port private_key public_key auth_type sudo sudo_password/;
  for my $key (@keys) {
    my $call = "get_$key";
    if ( ref($self)->can($call) ) {
      $new_auth{$key} = $self->$call();
    }
    else {
      $new_auth{$key} = $other_auth->{$key};
    }
lib/Rex/Interface/Connection/OpenSSH.pm view on Meta::CPAN
  bless( $self, $proto );
  return $self;
}
sub connect {
  my ( $self, %option ) = @_;
  my (
    $user, $pass,    $private_key, $public_key, $server,
    $port, $timeout, $auth_type,   $is_sudo
  );
  $user        = $option{user};
  $pass        = $option{password};
  $server      = $option{server};
  $port        = $option{port};
  $timeout     = $option{timeout};
  $public_key  = $option{public_key};
  $private_key = $option{private_key};
  $auth_type   = $option{auth_type};
  $is_sudo     = $option{sudo};
  $self->{server}        = $server;
  $self->{is_sudo}       = $is_sudo;
  $self->{__auth_info__} = \%option;
  Rex::Logger::debug("Using Net::OpenSSH for connection");
  Rex::Logger::debug( "Using user: " . $user );
  Rex::Logger::debug( Rex::Logger::masq( "Using password: %s", $pass ) )
lib/Rex/Interface/Connection/OpenSSH.pm view on Meta::CPAN
  {
    for my $_try_auth_type (@auth_types_to_try) {
      my @_internal_con_props = @connection_props;
      if ( $_try_auth_type eq "pass" ) {
        push @_internal_con_props, password => $pass;
      }
      elsif ( $_try_auth_type eq "key" ) {
        push @_internal_con_props, key_path => $private_key;
        if ($pass) {
          push @_internal_con_props, passphrase => $pass;
        }
      }
      $self->{ssh} =
        Net::OpenSSH->new( @_internal_con_props,
        %net_openssh_constructor_options );
      if ( $self->{ssh} && !$self->{ssh}->error ) {
lib/Rex/Interface/Connection/SSH.pm view on Meta::CPAN
  bless( $self, $proto );
  return $self;
}
sub connect {
  my ( $self, %option ) = @_;
  my (
    $user, $pass,    $private_key, $public_key, $server,
    $port, $timeout, $auth_type,   $is_sudo
  );
  $user        = $option{user};
  $pass        = $option{password};
  $server      = $option{server};
  $port        = $option{port};
  $timeout     = $option{timeout};
  $public_key  = $option{public_key};
  $private_key = $option{private_key};
  $auth_type   = $option{auth_type};
  $is_sudo     = $option{sudo};
  $self->{server}        = $server;
  $self->{is_sudo}       = $is_sudo;
  $self->{__auth_info__} = \%option;
  Rex::Logger::debug("Using Net::SSH2 for connection");
  Rex::Logger::debug( "Using user: " . $user );
  Rex::Logger::debug( Rex::Logger::masq( "Using password: %s", $pass ) )
lib/Rex/Interface/Connection/SSH.pm view on Meta::CPAN
        'username' => $user,
        'password' => $pass
      );
    }
  }
  elsif ( $auth_type && $auth_type eq "key" ) {
    Rex::Logger::debug("Using key authentication.");
    croak "No public_key file defined."  if !$public_key;
    croak "No private_key file defined." if !$private_key;
    $self->{auth_ret} =
      $self->{ssh}->auth_publickey( $user, $public_key, $private_key, $pass );
  }
  else {
    Rex::Logger::debug("Trying to guess the authentication method.");
    $self->{auth_ret} = $self->{ssh}->auth(
      'username'   => $user,
      'password'   => $pass,
      'publickey'  => $public_key  || "",
      'privatekey' => $private_key || ""
    );
  }
  $self->{sftp} = $self->{ssh}->sftp;
}
sub reconnect {
  my ($self) = @_;
  Rex::Logger::debug("Reconnecting SSH");
lib/Rex/Task.pm view on Meta::CPAN
 $task = Rex::Task->new(
   func => sub { some_code_here },
   server => [ @server ],
   desc => $description,
   no_ssh => $no_ssh,
   hidden => $hidden,
   auth => {
     user      => $user,
     password   => $password,
     private_key => $private_key,
     public_key  => $public_key,
   },
   before => [sub {}, sub {}, ...],
   after  => [sub {}, sub {}, ...],
   around => [sub {}, sub {}, ...],
   before_task_start => [sub {}, sub {}, ...],
   after_task_finished => [sub {}, sub {}, ...],
   name => $task_name,
   executor => Rex::Interface::Executor->create,
   opts => {key1 => val1, key2 => val2, ...},
lib/Rex/Task.pm view on Meta::CPAN
      undef, "0.40",
      "Defining extra credentials within the task creation is deprecated.",
      "Please use set auth => task => 'taskname' instead."
    );
    # use extra defined credentials
    my $data = pop(@server);
    $self->set_auth( "user",     $data->{'user'} );
    $self->set_auth( "password", $data->{'password'} );
    if ( exists $data->{"private_key"} ) {
      $self->set_auth( "private_key", $data->{"private_key"} );
      $self->set_auth( "public_key",  $data->{"public_key"} );
    }
  }
  if ( ref( $self->{server} ) eq "ARRAY"
    && scalar( @{ $self->{server} } ) > 0 )
  {
    for my $srv ( @{ $self->{server} } ) {
      if ( ref($srv) eq "CODE" ) {
        push( @ret, &$srv() );
lib/Rex/Task.pm view on Meta::CPAN
    my $data = $auth->{$key};
    $data = Rex::Logger::masq( "%s", $data ) if $key eq 'password';
    $data = Rex::Logger::masq( "%s", $data ) if $key eq 'sudo_password';
    $data ||= "";
    Rex::Logger::debug("$key => [[$data]]");
  }
  $auth->{public_key} = resolv_path( $auth->{public_key}, 1 )
    if ( $auth->{public_key} );
  $auth->{private_key} = resolv_path( $auth->{private_key}, 1 )
    if ( $auth->{private_key} );
  my $profiler = Rex::Profiler->new;
  # task specific auth rules over all
  my %connect_hash = %{$auth};
  $connect_hash{server} = $server;
  # need to get rid of this
  Rex::push_connection(
    {
lib/Rex/TaskList/Base.pm view on Meta::CPAN
    before_task_start   => [],
    name                => $task_name,
    executor            => Rex::Interface::Executor->create,
    connection_type     => Rex::Config->get_connection_type,
  );
  if ( $self->{DEFAULT_AUTH} ) {
    $task_hash{auth} = {
      user          => Rex::Config->get_user          || undef,
      password      => Rex::Config->get_password      || undef,
      private_key   => Rex::Config->get_private_key   || undef,
      public_key    => Rex::Config->get_public_key    || undef,
      sudo_password => Rex::Config->get_sudo_password || undef,
    };
  }
  if ( exists $Rex::Commands::auth_late{$task_name} ) {
    $task_hash{auth} = $Rex::Commands::auth_late{$task_name};
  }
  $self->{tasks}->{$task_name} = Rex::Task->new(%task_hash);
use Test::More tests => 140;
use Test::Warnings;
use Rex -feature => '0.31';
delete $ENV{REX_USER};
user("root3");
password("pass3");
private_key("priv.key3");
public_key("pub.key3");
key_auth();
no warnings;
is( Rex::TaskList->create()->is_default_auth(), 0, "default auth off" );
use warnings;
group( "foo", "server1", "server2", "server3" );
group( "bar", "serv[01..10]" );
group( "latebar", "server[01..03]" );
my $task       = Rex::TaskList->create()->get_task("authtest3");
my @all_server = @{ $task->server };
for my $server (@all_server) {
  my $auth = $task->merge_auth($server);
  is( $auth->{user},        "root3",     "merge_auth - user" );
  is( $auth->{password},    "pass3",     "merge_auth - pass" );
  is( $auth->{public_key},  "pub.key3",  "merge_auth - pub" );
  is( $auth->{private_key}, "priv.key3", "merge_auth - priv" );
  is( $auth->{auth_type},   "key",       "merge_auth - auth" );
}
pass_auth();
for my $server (@all_server) {
  my $auth = $task->merge_auth($server);
  is( $auth->{user},        "root3",     "merge_auth - user" );
  is( $auth->{password},    "pass3",     "merge_auth - pass" );
  is( $auth->{public_key},  "pub.key3",  "merge_auth - pub" );
  is( $auth->{private_key}, "priv.key3", "merge_auth - priv" );
  is( $auth->{auth_type},   "pass",      "merge_auth - auth" );
}
auth( for => "bar",     user => "jan", password => "foo" );
auth( for => "latebar", user => "jan", password => "foo" );
$task       = Rex::TaskList->create()->get_task("authtest1");
@all_server = @{ $task->server };
for my $server (@all_server) {
  my $auth = $task->merge_auth($server);
  is( $auth->{user},        "root3",     "merge_auth - user" );
  is( $auth->{password},    "pass3",     "merge_auth - pass" );
  is( $auth->{public_key},  "pub.key3",  "merge_auth - pub" );
  is( $auth->{private_key}, "priv.key3", "merge_auth - priv" );
}
$task       = Rex::TaskList->create()->get_task("authtest2");
@all_server = @{ $task->server };
for my $server (@all_server) {
  my $auth = $task->merge_auth($server);
  is( $auth->{user},        "jan",       "merge_auth - user" );
  is( $auth->{password},    "foo",       "merge_auth - pass" );
  is( $auth->{public_key},  "pub.key3",  "merge_auth - pub" );
  is( $auth->{private_key}, "priv.key3", "merge_auth - priv" );
  is( $auth->{auth_type},   "try",       "merge_auth - auth_type" );
  ok( !$auth->{sudo}, "merge_auth - sudo" );
}
$task       = Rex::TaskList->create()->get_task("authtest4");
@all_server = @{ $task->server };
for my $server (@all_server) {
  my $auth = $task->merge_auth($server);
  is( $auth->{user},        "jan",       "merge_auth - user - lategroup" );
  is( $auth->{password},    "foo",       "merge_auth - pass - lategroup" );
  is( $auth->{public_key},  "pub.key3",  "merge_auth - pub - lategroup" );
  is( $auth->{private_key}, "priv.key3", "merge_auth - priv - lategroup" );
  is( $auth->{auth_type},   "try",       "merge_auth - auth_type - lategroup" );
  ok( !$auth->{sudo}, "merge_auth - sudo - lategroup" );
}
auth(
  for         => "authtest1",
  user        => "deploy",
  password    => "baz",
  private_key => FALSE(),
  public_key  => FALSE(),
  sudo        => TRUE()
);
$task       = Rex::TaskList->create()->get_task("authtest1");
@all_server = @{ $task->server };
for my $server (@all_server) {
  my $auth = $task->merge_auth($server);
  is( $auth->{user},        "deploy", "merge_auth - user" );
  is( $auth->{password},    "baz",    "merge_auth - pass" );
  is( $auth->{public_key},  FALSE(),  "merge_auth - pub" );
  is( $auth->{private_key}, FALSE(),  "merge_auth - priv" );
  is( $auth->{auth_type},   "pass",   "merge_auth - auth_type" );
  is( $auth->{sudo},        TRUE(),   "merge_auth - sudo" );
}
set( "key1", "val1" );
is( get("key1"), "val1", "got value of key1" );
set( "key1", "val2" );
is( get("key1"), "val2", "got new value of key1" );
  $::QUIET = 1;
}
group( "srvgr1", "srv1" );
group( "srvgr2", "srv2", "srv3" );
delete $ENV{REX_USER};
user("root1");
password("pass1");
private_key("priv.key1");
public_key("pub.key1");
task(
  "testa1",
  sub {
  }
);
user("root2");
password("pass2");
private_key("priv.key2");
public_key("pub.key2");
auth(
  for         => "srvgr1",
  user        => "foouser",
  password    => "foopass",
  private_key => "foo.priv",
  public_key  => "foo.pub"
);
task(
  "testb1",
  group => "srvgr1",
  sub {
  }
);
);
task(
  "testa2",
  sub {
  }
);
user("root3");
password("pass3");
private_key("priv.key3");
public_key("pub.key3");
task(
  "testa3",
  sub {
  }
);
my $auth = Rex::TaskList->create()->get_task("testa1")->{auth};
is( $auth->{user},        "root1" );
is( $auth->{password},    "pass1" );
is( $auth->{private_key}, "priv.key1" );
is( $auth->{public_key},  "pub.key1" );
$auth = Rex::TaskList->create()->get_task("testa2")->{auth};
is( $auth->{user},        "root2" );
is( $auth->{password},    "pass2" );
is( $auth->{private_key}, "priv.key2" );
is( $auth->{public_key},  "pub.key2" );
$auth = Rex::TaskList->create()->get_task("testa3")->{auth};
is( $auth->{user},        "root3" );
is( $auth->{password},    "pass3" );
is( $auth->{private_key}, "priv.key3" );
is( $auth->{public_key},  "pub.key3" );
my $task_b1 = Rex::TaskList->create()->get_task("testb1");
$auth = $task_b1->{auth};
is( $auth->{user},        "root2" );
is( $auth->{password},    "pass2" );
is( $auth->{private_key}, "priv.key2" );
is( $auth->{public_key},  "pub.key2" );
my $servers = $task_b1->server;
for my $server ( @{$servers} ) {
  $auth = $task_b1->merge_auth($server);
  is( $auth->{user},        "root2" );
  is( $auth->{password},    "pass2" );
  is( $auth->{private_key}, "priv.key2" );
  is( $auth->{public_key},  "pub.key2" );
}
my $task_b2 = Rex::TaskList->create()->get_task("testb2");
$servers = $task_b2->server;
for my $server ( @{$servers} ) {
  $auth = $task_b2->merge_auth($server);
  is( $auth->{user},        "root2" );
  is( $auth->{password},    "pass2" );
  is( $auth->{private_key}, "priv.key2" );
  is( $auth->{public_key},  "pub.key2" );
}
my $task_b3 = Rex::TaskList->create()->get_task("testb3");
$servers = $task_b3->server;
for my $server ( @{$servers} ) {
  $auth = $task_b3->merge_auth($server);
  is( $auth->{user},        "root2" );
  is( $auth->{password},    "pass2" );
  is( $auth->{private_key}, "priv.key2" );
  is( $auth->{public_key},  "pub.key2" );
}
auth(
  for         => "testa4",
  user        => "baruser",
  password    => "barpass",
  private_key => "testa4.priv",
  public_key  => "testa4.pub"
);
task(
  "testa4",
  sub {
  }
);
$auth = Rex::TaskList->create()->get_task("testa4")->{auth};
is( $auth->{user},        "baruser" );
is( $auth->{password},    "barpass" );
is( $auth->{private_key}, "testa4.priv" );
is( $auth->{public_key},  "testa4.pub" );
$ENV{REX_USER} = "root5";
user("toor5");
password("pass5");
private_key("testa5.priv");
public_key("testa5.pub");
task(
  "testa5",
  sub {
  }
);
$auth = Rex::TaskList->create()->get_task("testa5")->{auth};
is( $auth->{user},        "root5" );
is( $auth->{password},    "pass5" );
is( $auth->{private_key}, "testa5.priv" );
is( $auth->{public_key},  "testa5.pub" );
t/commands.t view on Meta::CPAN
is( Rex::Config->get_timeout, 5, "setting timeout" );
max_connect_retries(5);
is( Rex::Config->get_max_connect_fails, 5, "setting max connect retries" );
is( length( get_random( 5, 'a' .. 'z' ) ), 5, "get random string" );
public_key("/tmp/pub.key");
is( Rex::Config->get_public_key, "/tmp/pub.key", "set public key" );
private_key("/tmp/priv.key");
is( Rex::Config->get_private_key, "/tmp/priv.key", "set private key" );
pass_auth();
ok( Rex::Config->get_password_auth, "password auth" );
parallelism(5);
is( Rex::Config->get_parallelism, 5, "set parallelism" );
parallelism(1);
path( "/bin", "/sbin" );
is_deeply( [ Rex::Config->get_path ], [qw!/bin /sbin!], "set path" );
use Test::Deep;
use Rex -feature => '0.31';
use Rex::Group;
use Symbol;
delete $ENV{REX_USER};
user("root3");
password("pass3");
private_key("priv.key3");
public_key("pub.key3");
no warnings;
$::FORCE_SERVER = "server1 foo[01..10]";
use warnings;
group( "forcetest1", "bla1", "blah2", "bla1" );
task( "tasktest3", "group", "forcetest1", sub { } );
is( $all_server[0],  "server1", "forceserver - task - 0" );
is( $all_server[1],  "foo01",   "forceserver - task - 1" );
is( $all_server[5],  "foo05",   "forceserver - task - 5" );
is( $all_server[10], "foo10",   "forceserver - task - 10" );
for my $server (@all_server) {
  my $auth = $task->merge_auth($server);
  is( $auth->{user},        "root3",     "merge_auth - user" );
  is( $auth->{password},    "pass3",     "merge_auth - pass" );
  is( $auth->{public_key},  "pub.key3",  "merge_auth - pub" );
  is( $auth->{private_key}, "priv.key3", "merge_auth - priv" );
}
auth( for => "tasktest3", user => "jan", password => "foo" );
for my $server (@all_server) {
  my $auth = $task->merge_auth($server);
  is( $auth->{user},        "jan",       "merge_auth - user" );
  is( $auth->{password},    "foo",       "merge_auth - pass" );
  is( $auth->{public_key},  "pub.key3",  "merge_auth - pub" );
  is( $auth->{private_key}, "priv.key3", "merge_auth - priv" );
}
group( "duplicated_by_list", "s[1..3,2..4]" );
my @cleaned_servers = Rex::Group->get_group("duplicated_by_list");
is_deeply [ $cleaned_servers[0]->get_servers ], [
  qw/
    s1 s2 s3 s4
    /
  ],
  "duplicated_by_list";