Jeevan Dongre
Jeevan Dongre

Reputation: 4649

automated deployments using chef

I am running my ruby on rails e-commerce application running on couple of ec2 instances in the production. I have not enabled auto scaling since we do Continuous Integration, we do deployment when ever required. I using chef for the all the reasons. I am trying to figure out how to use chef to deploy code to the multiple ec2 instances automcatically and manual intervention. I tried to deploy the code during the initial ec2 instance works fine. But my question is how do I do it in the auto scaling mode so that instance pull the latest code from either github or bit bucket and deployes itseld after bundle updating and all.

Upvotes: 1

Views: 2181

Answers (1)

slayedbylucifer
slayedbylucifer

Reputation: 23492

Fair enough. This is what i do and it works fine:

I have created an AMI with below settings:

  1. install chef client

  2. Create /etc/chef directory

  3. Copy your_company-validator.pem from chef workstation to AMI at /etc/chef/validation.pem
  4. Create /etc/chef/client.rb as below.

If you use chef-solo, make the changes accordingly.

cat >> /etc/chef/client.rb <EF
log_level        :auto
log_location     STDOUT
chef_server_url  "https://api.opscode.com/organizations/your_company"
validation_client_name "you_company-validator"
EF

Now, you have all above stuff configured in the AMI for chef bootstrap.

When you launch the AMI (using autoscaling or any other way), provide user-data where in it will run the chef-client with run_list of your choice. I provide below user-data:

#!/bin/bash
cat > /etc/chef/firstboot.json << EOL
{"run_list": ["recipe[java::oracle]"]}
EOL
chef-client -j /etc/chef/firstboot.json > /tmp/initialize_client.log 2>&1

basically, I am creating a .json file where I would specify the recipe/role/run_list I want to run. Once you provide the user-data, it will get executed on the 1st boot and chef-client will be run along with the run_list.

I think this is what you are looking for. so to summarize:

  1. Create an AMI with pre-installed chef-client, client.rb and validation.pem
  2. and then provide user-data at the time of instance launch.

This works perfectly for me. Let me know if this set-up gives you any trouble. I have been using this for quite some time.

So when I launch my instance using autscaling, it gets automatically chef-bootstrapped along with the recipes of my choice.

ASSUMPTION: you have all your recipes/roles created on chef-server before doing this. else the bootstrap will eventually fail.

Upvotes: 6

Related Questions