Chef Advanced - Setup and Installation
There was an earlier post in which we were able to install chef in no time, but now we will dig deeper and understand what exactly happens so that we have more control over this process.
Firstly we will start off by installing VirtualBox, Vagrant, Git and Ruby on a linux machine, I am using Ubuntu today to demonstrate this.
Lets confirm our Ubuntu version before we install the VirtualBox using the below
We go to this download page for VirtualBox to get the link for the virtualBox that we would like to have installed. Before we run the single line command to install VirtualBox, lets just ensure that the system is upto date.
And then also Confirm that VirtualBox is not already installed and running.
And then the magically formulation to have it all installed in a single command!
And here is Virtualbox
to launch it from terminal, just type
wget http://files.vagrantup.com/packages/7ec0ee1d00a916f80b109a298bab08e391945243/vagrant_1.2.7_x86_64.deb | sudo dpkg --install vagrant_1.2.7_x86_64.deb
vagrant -v
And the final command
Firstly we will start off by installing VirtualBox, Vagrant, Git and Ruby on a linux machine, I am using Ubuntu today to demonstrate this.
Installing VirtualBox and getting Ubuntu ready to receive it.
I have tried to do this in two ways, one of easiest way of doing this by going to the terminal and entering
sudo apt-get install virtualbox
The more detailed Version is as below, which will give us more control so that we could be as precise as possible with versions and dependencies.
Lets confirm our Ubuntu version before we install the VirtualBox using the below
lsb_relase -a
We go to this download page for VirtualBox to get the link for the virtualBox that we would like to have installed. Before we run the single line command to install VirtualBox, lets just ensure that the system is upto date.
sudo apt-get update
And then also Confirm that VirtualBox is not already installed and running.
And then the magically formulation to have it all installed in a single command!
wget http://download.virtualbox.org/virtualbox/4.3.6/virtualbox-4.3_4.3.6-91406~Ubuntu~precise_amd64.deb | sudo dpkg --install virtualbox-4.3_4.3.6-91406~Ubuntu~precise_amd64.deb
And here is Virtualbox
to launch it from terminal, just type
sudo VirtualBox
Troubleshooting
If you have some trouble installing VirtualBox in this way, running the below command should help in fixing anything that is broken.
sudo apt-get --install -f
Now Installing Vagrant on Ubuntu!
The simple way of doing it is:
sudo apt-get install vagrant
To get more control on this i.e. for example if I want to install the vagrant version 1.2.7_x86_64.deb while the latest one is 1.3.5 and that is what gets installed through the above command.
Go to the Terminal and put in the following command, I got the link by manually going to the download page.
wget http://files.vagrantup.com/packages/7ec0ee1d00a916f80b109a298bab08e391945243/vagrant_1.2.7_x86_64.deb | sudo dpkg --install vagrant_1.2.7_x86_64.deb
And confirm that vagrant is installed by using the command
vagrant -v
Almost there, check if GIT is installed too !
Git is the version control we will be using. Its an awesome tool! You can check about it on this link here.
Just a few commands used
sudo apt-get install git
git --version
the first one is to install Git and the latter is used to just confirm that Git is installed and is giving us the version number.
Installing Chef! Finally!
In one of my earlier posts here, we see how we can install chef in just a few seconds!
But to get finer control and to know what exactly is happening, lets do it the long way here.
Just before we go ahead and jump in, lets take a peek at Chef's definition
Chef is a systems and cloud infrastructure automation framework that makes it easy to deploy servers and applications to any physical, virtual, or cloud location, no matter the size of the infrastructure. Each organization is comprised of one (or more) workstations, a single server, and every node that will be configured and maintained by the chef-client. Cookbooks (and recipes) are used to tell the chef-client how each node in your organization should be configured. The chef-client (which is installed on every node) does the actual configuration.And it is written in a programming language called Ruby so we will now install rbenv which is the Ruby Version Manager that will provide us some virtual environments to have multiple versions of Ruby on our system and the ability to easily switch between them.
We start off by first installing the support package
sudo apt-get install build-essential zlib1g-dev
Followed by installing the rbenv from the official git repository and add it to your path
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile
echo 'eval "$(rbenv init -)"' >> .bash_profile
and reloading our bash profile
source ~/.bash_profile
Installing Ruby-build now
git clone git://github.com/sstephenson/ruby-build.git
cd ruby-build
./install.sh
Now installing the target Ruby version
rbenv rehash
rbenv install 1.9.3-p385
rbenv shell 1.9.3-p385
rbenv global 1.9.3-p385
gem install chef
rbenv rehash
Congratulate yourself for getting the chef to cook meals for you in the future!
TroubleShooting!
In case of error like this just do the following, (that is the reason I have included zlib the support packages that we downloaded a while ago.
~$ gem install chef
ERROR: Loading command: install (LoadError)
cannot load such file -- zlib
ERROR: While executing gem ... (NameError)
uninitialized constant Gem::Commands: :InstallCommand
ERROR: Loading command: install (LoadError)
cannot load such file -- zlib
ERROR: While executing gem ... (NameError)
uninitialized constant Gem::Commands:
rbenv uninstall 1.9.3-p286
rbenv install 1.9.3-p286
gem install chef
Another error that could come up are
Error: While Generating Documentation for pry-0.9.12.6
Message: Undefined method name for #<RDoc::RubyToken::TKDOT:......
I just put in the "gem install chef" command again and this resolved the issue,
But one interesting observation is the number of Ruby gems before installing chef and after!
After gem install chef!