Rex-JobControl

 view release on metacpan or  search on metacpan

lib/Rex/JobControl/Helper/Project/Rexfile.pm  view on Meta::CPAN


  chwd "$rex_path/$rexfile", sub {
    my $rex_cmd = $self->project->app->config->{rex};
    my $out     = `$rex_cmd -Ty`;
    $rex_info = YAML::Load($out);
  };

  my $rex_configuration = {
    name    => $self->name,
    url     => $url,
    rexfile => $rexfile,
    rex     => $rex_info,
  };

  YAML::DumpFile( "$rex_path/rex.conf.yml", $rex_configuration );

}

sub remove {
  my ($self) = @_;
  my $rexfile_path = File::Spec->catdir( $self->project->project_path,
    "rex", $self->{directory} );

  File::Path::remove_tree($rexfile_path);
}

sub execute {
  my ( $self, %option ) = @_;

  my $task   = $option{task};
  my $job    = $option{job};
  my @server = @{ $option{server} };
  my $cmdb   = $option{cmdb};

  if ( scalar @server == 0 ) {
    @server = ("<local>");
  }

  my $rex_path = File::Spec->catdir( $self->project->project_path,
    "rex", $self->{directory}, $self->rexfile );

  $self->project->app->log->debug("rex_path: $rex_path");

  my @ret;

  my $all_server = $self->project->all_server;

  for my $srv (@server) {

    my ($srv_object) = grep { $_->{name} eq $srv } @{$all_server};

    if ( exists $srv_object->{auth} ) {
      if ( exists $srv_object->{auth}->{auth_type} ) {
        $ENV{REX_AUTH_TYPE} = $srv_object->{auth}->{auth_type};
      }

      if ( exists $srv_object->{auth}->{public_key} ) {
        $ENV{REX_PUBLIC_KEY} = $srv_object->{auth}->{public_key};
      }

      if ( exists $srv_object->{auth}->{private_key} ) {
        $ENV{REX_PRIVATE_KEY} = $srv_object->{auth}->{private_key};
      }

      if ( exists $srv_object->{auth}->{user} ) {
        $ENV{REX_USER} = $srv_object->{auth}->{user};
      }

      if ( exists $srv_object->{auth}->{password} ) {
        $ENV{REX_PASSWORD} = $srv_object->{auth}->{password};
      }

      if ( exists $srv_object->{auth}->{sudo_password} ) {
        $ENV{REX_SUDO_PASSWORD} = $srv_object->{auth}->{sudo_password};
      }

      if ( exists $srv_object->{auth}->{sudo} ) {
        $ENV{REX_SUDO} = $srv_object->{auth}->{sudo};
      }

    }

    $ENV{JOBCONTROL_PROJECT_PATH} = $self->project->project_path;

    my $child_exit_status;
    chwd $rex_path, sub {
      my ( $chld_out, $chld_in, $pid );

      $self->project->app->log->debug(
        "Writing output to: $ENV{JOBCONTROL_EXECUTION_PATH}/output.log");

      my $out_fh =
        IO::File->new( "$ENV{JOBCONTROL_EXECUTION_PATH}/output.log", "a+" );
      my $err_fh =
        IO::File->new( "$ENV{JOBCONTROL_EXECUTION_PATH}/output.log", "a+" );
      capture {
        system( $self->project->app->config->{rex},
          '-H', $srv, '-t', 1, '-F', '-c', '-m',
          ( $cmdb ? ( '-O', "cmdb_path=$cmdb/jobcontrol.yml" ) : () ), $task );

        $child_exit_status = $?;
      }
      stdout => $out_fh, stderr => $err_fh;

    };

    if ( $child_exit_status == 0 ) {
      push @ret,
        {
        server  => $srv,
        rexfile => $self->name,
        task    => $task,
        status  => "success",
        };
    }
    else {
      push @ret,
        {
        server  => $srv,
        rexfile => $self->name,
        task    => $task,
        status  => "failed",

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.139 second using v1.00-cache-2.02-grep-82fe00e-cpan-f73e49a70403 )