Installing knife ec2 plugin on chefdk

Today I decided to test the chef development kit. Chef released chefdk 0.3.6 version on 2015/01/20. Till now I used to install and upgrade chef manually installing all required gems. What I found out is that knife ec2 plugin is not bundled with chefdk so you ‘ll have to install it yourself which is not very difficult. You only need to execute the following command

 $ /opt/chefdk/embedded/bin/gem install knife-ec2 

Executing MySQL load data once on chef using tags

Recently I have been trying to cut off expanses in one of the projects I ve been working. So we decided to move two of the t1.micro ec2 AWS instances to our dedicated server,which was already hosting VMS for other projects, as one KVM guest. First instance was the production MySQL DB server for the project while the other was the webserver(apache) hosting our php application. I thought it would be great to have the whole migration automated with chef in case we need to migrate later back to AWS or to another dedicated server.

Continue reading

How to set memcached CACHESIZE via chef based on node’s memory

Let’s say you wish to set the memcached CACHESIZE variable based on your system’s(node) memory.
By default CACHESIZE is defined as 64MB. You get the nodes total memory using the node[‘memory’][‘total’] which will return the memory in KB for example 1019492kB In this case you need to divide it with 1024 to get the size in MB. If you want to assign 10% of your total memory to memcached CACHESIZE then you ll have 1019492kB * 0.1 / 1024 = 99.559MB. You can remove the .559 using ruby’s to_i method.

So you can put the following in your cookbook to set your memcached cachesize. The only dependency is opscode memcached cookbook

node.set['memcached']['memory'] = (node['memory']['total'].to_i * 0.1 / 1024).to_i
include_recipe 'memcached'