Pantry

 view release on metacpan or  search on metacpan

lib/Pantry/App/Command/sync.pm  view on Meta::CPAN

  my $ssh = Net::OpenSSH->new($host, port => $port, user => $user);
#  $Net::OpenSSH::debug = 255;
  die "Couldn't establish an SSH connection: " . $ssh->error . "\n"
    if $ssh->error;

  # ensure destination directory and ownership
  my $dest_dir = $self->_remote_pantry_dir;
  $ssh->system($sudo . "mkdir -p $dest_dir")
    or die "Could not create $dest_dir\n";
  if ( $sudo ) {
    $ssh->system($sudo . "chown $user $dest_dir")
      or die "Could not chown $dest_dir to $user\n";
  }

  # generate local solo.rb and rsync it to /etc/chef/solo.rb
  my ($fh, $solo_rb) = tempfile( "pantry-solo.rb-XXXXXX", TMPDIR => 1 );
  print {$fh} $self->_solo_rb_guts;
  close $fh;
  $ssh->rsync_put($rsync_opts, $solo_rb, "$dest_dir/solo.rb")
    or die "Could not rsync solo.rb\n";

  # prepare node JSON for upload

lib/Pantry/App/Command/sync.pm  view on Meta::CPAN

  # rsync databags to remote /var/chef-solo/data_bags
  $ssh->rsync_put($rsync_opts, "data_bags", $dest_dir)
    or die "Could not rsync data_bags\n";

  # ssh execute chef-solo
  my $command = $sudo_i . "chef-solo -c $dest_dir/solo.rb";
  $command .= " -l debug" if $ENV{PANTRY_CHEF_DEBUG};
  $ssh->system({tty => $sudo ? 1 : 0}, $command) # XXX eventually capture output
    or die "Error running chef-solo\n";
  # cleanup report permissions if running under sudo so we can find/download it
  $ssh->system($sudo . "chown -R $user $dest_dir/reports") if $sudo;
  # scp get run report
  my $report = $ssh->capture("ls -t $dest_dir/reports | head -1");
  chomp $report;
  # XXX should check that the report timestamp makes sense -- xdg, 2012-05-03

  dir("reports")->mkpath;
  $ssh->rsync_get($rsync_opts, "$dest_dir/reports/$report", "reports/$name");

  if ( $opt->{reboot} ) {
    $ssh->system($sudo . "shutdown -r now");



( run in 1.638 second using v1.01-cache-2.11-cpan-71847e10f99 )