use Amazon EC2 tools in Capistrano to get the servers to push the code

use Amazon EC2 tools in Capistrano to get the servers to push the code

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)
 for(i=0;i<workers-array.len;i++){
     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.

Antwort1

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")
end

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

verwandte Informationen