Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy a file to a bunch of servers with capistrano

I use cap invoke a lot to run commands on a bunch of servers. I would like to also use capistrano to push a single file to a bunch of servers.

At first I thought that PUT would do it, but put makes you create the data for the file. I don't want to do this, I just want to copy an existing file from the machine where I'm running the capistrano comand to the other machines.

It would be cool if I could do something like this:

host1$ cap HOSTS=f1.foo.com,f2.foo.com,f3.foo.com COPY /tmp/bar.bin 

I would expect this to copy host1:/tmp/bar.bin to f1.foo.com:/tmp/bar.bin and f2.foo.com:/tmp/bar.bin and f3.foo.com:/tmp/bar.bin

This kind of thing seems very useful so I'm sure there must be a way to do this...

like image 395
Adam Avatar asked Jun 14 '11 00:06

Adam


2 Answers

upload(from, to, options={}, &block)

The upload action stores the file at the given path on all servers targeted by the current task.

If you ever used the deploy:upload task before, then you might already know how this method works. It takes the path of the resource you want to upload and the target path on the remote servers.

desc "Uploads CHANGELOG.txt to all remote servers."
task :upload_changelog do
  upload("#{RAILS_ROOT}/CHANGELOG.txt", "#{current_path}/public/CHANGELOG")
end

source

like image 198
yacc Avatar answered Nov 11 '22 09:11

yacc


This uploads all files to the respective servers.

cap deploy:upload FILES=abc,def

like image 1
Sairam Avatar answered Nov 11 '22 09:11

Sairam