I am trying to use EC2 tools to get all the machines with a particular tag in some type of array in /config/deploy/prod.rb file in Capistrano. Something like this:

In prod.rb file:

//untested command
workers-array[]=$(ec2-describe-instances -F vpc-id=1234 -F tag:Env=prod -F     tag:SystemType=worker)
     role :worker-A, workers-array[i]

I am not sure how we can do this in capistrano, am new to ruby too. Guys any help on this would be really appreciated.

  • Did you ever come up with a solution to this? I'm not a cap hacker, the best I've done is to write a script to generate the lists of hosts using the API Dec 20 '12 at 19:01
  • @GaryRichardson I did the same thing; bash script which uses Amazon API and get all the workers. Plus I moved away from Capistrano and use bash now to deploy code.
    – APZ
    Dec 20 '12 at 20:46

I recently ran into the same issue, or had similar thoughts. Ran into this question while working with something else.

So I wanted to run certain puppet configurations based on the type of server it was configured for. It should be fairly simple to do something similar but use attributes for running different tasks depending on the situation.

I set up so that the servers are described as usual in Capistrano, like:

role :web, "mywebhost" #attributes to the server can be added at the end

Then I created a task for bootstraping all servers to make sure they had puppet. After that I added commands to run after the bootstrap task, and on which role. These conditions can take advantage of attributes.

after "bootstrap", :roles=>[:web] do 
   # here we place code specific for configuring the web role using puppet
   try_sudo("puppet apply config/puppet/web.pp")

You can look at the following link for inspiration for running task based on attributes: pulling puppets strings with capistrano

This example is for puppet, but you could just disregard puppet and create the capistrano structure that you want.

I have a test repo set up on github describing this. I still have to add the readme but you should find what you need here: capdriven-puppet

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.