Some time ago I started playing with excellent tool vagrant. In this post I will show how to setup chef server using vagrant.


I assume that you know what is vagrant [vagrant]( "Vagrant") and chef [opscode]( "Chef")


One of the problems with chef that it depends on unique hostname. Vagrant discussion [ticket]( "Ticket"), suggests that it's job of the provisioner to setup hostname. But if you tried to use chef to change hostname in two step:

* change hostname

* change domainname

as I tried initially, chef will breaks between those two steps.

Following example on [agiletesting]( "Agile Testing").

I wrote a small `hosts:chefserver` receipt, available on [github]( "Github"), which changes hostname and domain name in one go using `node_name`.

#!/bin/bashHOSTNAME=$1hostname $HOSTNAMEecho $HOSTNAME> /etc/hostnameIPADDR=`ifconfig  | grep 'inet addr:'| grep -v '' | cut -d: -f2 | awk '{ print $1}'`echo $IPADDR >/tmp/ip_currentsed -i "s/[[:space:]]localhost/    localhost\n$IPADDR  $ $HOSTNAME\n/g" /etc/hostssed -i "s/   vagrantup/$IPADDR  $ $HOSTNAME\n/g" /etc/hosts

And full vagrant code for test deployment of chefserver:

config.vm.define :chefserver do |chefserver_config|"base"    chefserver_config.vm.provisioner=:chef_solo    chefserver_config.vm.forward_port("chefs", 4000, 4000)    chefserver_config.vm.forward_port("chefs_web", 4040, 4040)      chefserver_config.vm.forward_port("ssh", 22, 2223,:auto => true)       chefserver_config.chef.node_name="chefserver"    chefserver_config.chef.cookbooks_path = ["cookbooks","other_cookbooks"]    chefserver_config.chef.run_list.clear    chefserver_config.chef.add_recipe("hosts::chefserver")    chefserver_config.chef.add_recipe("apt")    chefserver_config.chef.add_recipe("build-essential")    chefserver_config.chef.add_recipe("chef::bootstrap_server")    chefserver_config.chef.json.merge!({       :chef=> {        :server_url=> "http://chefserver.*.com:4000",        :webui_enabled=> true,       }      })   end


comments powered by Disqus