I’m trying to configure Capistrano to do the same task on two different servers, each of them having different credentials. I’d like to do something simmilar to:
namespace :deploy do
role :db, "192.168.1.1", :credentials => "db1.yml"
role :db, "192.168.1.1", :credentials => "db2.yml"
task :mytask, :roles => :db do
credentials = YAML.load_file(something)
...
Is that possible? What should I substitute something with, in order to access the current server configuration?
OK, I finally had some time to solve this. Hopefully someone else will find this answer useful. Here’s how i eventually solved the problem:
I see now that I may had stated the question in a confusing way – that’s because I hadn’t understood, that task are run concurrently.
This will in fact execute the task (here
puts credentials) once for each server, which was what I was trying to do.Output:
It’s a good idea to add a filter to a task so it won’t run if the server has no credentials.
That being said, making everybody in the team maintain current (and for security reasons non-versioned) credentials to all servers turned out to be too much hassle (thus defeating the idea of using Capistrano). Now instead of keeping the external configuration on the disks of users I’m going to keep the data on the servers affected (mostly in form of runnable scripts with all credentials hidden inside). Like this: