Posts

Showing posts with the label Chef

Mongorestore using knife

This post is a continuation to my post Taking a Mongodump using Knife . Keeping the assumptions the same as the previous post, this post outlines a knife plugin to restore your mongo database from a dump taken as above. module KnifePlugins   class MongoDumpApply < Chef::Knife     banner 'knife mongo dump apply'         option :db_env,       :long => '--db-env DB_ENV',       :description => 'Environment to apply the dump to'      option :dump_dir,       :long => '--dump-dir DUMP_DIR',       :description => 'Full path to dump location'    deps do       require 'chef/search/query'    end     def run       @dump_dir = config[:dump_dir]       @env = config[:db_env]      if !vali...

Mongodump and upload to S3 using knife

Quite recently I have had to write a knife plugin to take mongo dumps. This post contains the code for the same with a few assumptions in place. Assumptions: 1.  CentOS 6.3, mongo db version 2.4.1 2.  Chef environment has the db config as below :      override_attributes({ database:  { user: 'db_user',                  dump_dir: '/opt/mongodb-dump',                  auth: true,                  replica: {                         id: 'rsTest',                         mongo_primary:'x.x...

AWS VPC - Basic Set Up

This blog is a collection of notes that were taken while settings up a virtual private cloud in AWS. The scenario presented here is described as below A chef server for configuration management. Jenkins CI server. Knife plugins to create and deploy application artifact. Load Balanced Web servers. DB servers. The AWS VPC scenario is Scenario 2 .   Most of the basic setup is mentioned in the article above. The basic parts of this setup are as follows PUBLIC NETWORK This network is exposed to the internet. Each node set up in the public network can talk to the internet (outbound). For inbound traffic, each node needs to be associated with an Elastic IP. Each node should have the Ephemeral Ports open since ACLs are stateless. Ephemeral ports are ports opened on the client end when the client machine tries to connect to a server machine on a specific port. PRIVATE NETWORK This network is a protected network. Mostly used to host back-end servers like databas...

Deploying an RoR app using Jenkins and Knife

The simplest way to deploy a Ruby on Rails app would be to package the deploy-able code into a tar and un-tar it at the server location. This can be achieved using rake but rake doesn't provide ssh ability. Another way is to use rake with Capistrano, but this would be useful when implementing a master-less puppet or chef-solo system for configuration management. Working on an RoR project, recently we discovered another approach to deploy an RoR app - using a custom knife plugin. There is a chef-deploy resource provided by chef which requires git repository access. Standards suggest that there should not be any development tools installed on the application server such as git etc. A series of discussions led us to decide on a chef based approach as we already had chef server managing the configuration on the nodes. Place the following knife plugin in the code repository's .chef/plugins/knife directory. Knife will automatically load the plugin. Configure jenkins as a knife ...

Cookbook Testing using Vagrant

There came a time in our team where we started churning out cookbooks by the hour. Now the question that needed to be answered was - How does one QA a chef cookbook. We could either have had one team member solely responsible for writing out rspecs and testing the cookbooks on a virtual environment, but what happens when the only team members who can be used to perform the above task as busy creating the cookbooks themselves. We needed a faster and smoother answer. In came Vagrant. Well Vagrant does everything that one would need to do to set up a virtual environment without wasting time in installations, snapshots, teardowns etc. Vagrant gives us one file "Vagrantfile" that needs to be configured with the environment that needs to be set and voila! everything works like you want it to. The standard (read easiest) way to use vagrant is as below. Create a directory where you want to store all your vagrant data, I call it vagrant. Then download the boxes that you need in y...

Deploy Application via Chef

After creating the Ruby on Rails application mentioned in my blog , the next task was to deploy the application to a hosted web server. The traditional way would be to write rake tasks and trigger them manually or using a CI build/deploy. Well chef provides another easy solution to deploy an application. The recipe below performs all the tasks of deploying an application. The before_migrate script contains the tasks that need to be performed before the application kicks in. The migration_command is the final command that is run to mark deployment successful. deploy_revision is used to make sure that the recipe would only be executed once the git head changes in the repository from the last deployed version. symlink_before_migrate can be used to create symlinks to the yml files used in the configuring the application. The deploy cookbook for a basic app looks like below app_user="user" deploy_dir="/opt/application_deploy" user app_user directory "/home...