Trying to write a task to distribute files from a remote server to a group of other remote servers

13 views
Skip to first unread message

Steve Wechsler

unread,
Jun 1, 2015, 5:12:53 PM6/1/15
to capis...@googlegroups.com
Versions:
  • Ruby 1.8.7
  • Capistrano v2.5.5
  • Rake / Rails / etc
Platform:
  • CentOS/Red Hat

I'm trying to write a task (to be called from a Perl script) that will work on any Linux host in my environment. However, since there is only one host that can SSH to every other host (it can also receive SSH connections from any host), and I can't guarantee that the task will be running on that host, I need to find a way to run the task on that host.

Here's what I came up with so far:


set :user, usr

cmd = "getpass " + user
set :password, `#{cmd}`

task :distribute, :on_error => :continue do
  host_list = hosts.split(',')
  servers = []
  host_list.each do |n|
    servers.push([n])
  end
  filelist=files.split(',')
  filelist.each do |f|
    upload f, target_dir, { :via => :scp, :hosts => servers, :on_error => :continue  }
  end
end

to be invoked like this:

/usr/bin/cap -f distribute_file.rb -S usr=user_to_run_as -s target_dir=/path/to/target -s files=/path/to/source_file -s hosts=(list of hosts) HOST=master_host

but that caused it to only run against master_host

So then I tried executing it with SSH, but that had a tendency to hang, plus it seemed to me like there should be a built-in method for this.

I'm a Perl guy and am new to both Ruby and capistrano, so please be gentle :)

Thanks.

Lee Hambley

unread,
Jun 1, 2015, 5:16:48 PM6/1/15
to Capistrano
I'd drop Capistrano and use SSHKit, the underlying driver in Capistrano v3 (your example is v2) - see https://github.com/capistrano/sshkit/blob/master/EXAMPLES.md#upload-a-file-from-disk and https://github.com/capistrano/sshkit/blob/master/EXAMPLES.md#using-with-rake

Combine those two to recreate what you have above, and mix in some https://github.com/capistrano/sshkit#tunneling-and-other-related-ssh-themes to make sure that you can reach the hosts as you need to, and I think you'll be fine. 

SSH is probably hanging because your process is hanging onto some resources, that can often be solved by tunneling and/or remotely starting thigns with `ssh me@thehost 'thecommand'`, for example. Hard to say without more info.

But, I'd absolutely avoid using Cap v2 if you're starting out, it's more than two years since EOL, but very widely documented/blogged about in the net.

--
You received this message because you are subscribed to the Google Groups "Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capistrano+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/capistrano/5014b7b3-78f4-44ed-9099-6fce08743222%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steve Wechsler

unread,
Jun 2, 2015, 10:03:24 AM6/2/15
to capis...@googlegroups.com
Thanks for the response. Can SSHkit be installed (I'm not the sysadmin) without breaking the existing Cap v2 installation? We have a lot of stuff depending on the latter.

Steve

Lee Hambley

unread,
Jun 2, 2015, 12:14:56 PM6/2/15
to Capistrano
SSHKit belongs on the client machines driving the SSH connection, not on the servers to which you connect. If you're running SSHKit *on* a server, along side Capistrano (also not typically installed on servers) then it'll be fine. Various versions of Capistrano 3 have various requirements on various version of SSHKit, but Capistrano two is unaware of SSHKit and it will not interfere.

--
You received this message because you are subscribed to the Google Groups "Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capistrano+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages