##Session 2: Provisioning Test Environment with Chef and Vagrant
The aim of this session is to help Tester to quickly set up Test / Dev environment on their own machine and share the configuration among team members.
####Agenda:
- Common Tasks on setting up new Dev/Test Environment (without Chef/Vagrant)
- Iteration 0: Prepare tools and ingredients
- Iteration 1: First taste of Vagrant - Chef using default setting
- Iteration 2: Adding some sugar - using available recipes
- Iteration 3: Little bit of chilli - creating your first recipe
- Iteration 4: Last check before committing
- Iteration 5: Integrating the provision to project
####Installation Instruction ######Prerequisite packages:
- Install Vagrant
Choose Vagrant for your prefer OS. - Install Virtualbox
- Install ChefDK
- Install DevKit (Windows user only)
This package is to support Ruby to build native package (for gem installation).
You should choose a non-space in full path as the destination for the kit. i.e C:\Hashicorp\DevKit
Then go to the DevKit folder to run devkitvars.bat
######Important time saving note Since creating first virtual machine would trigger downloading of hundred of megabytes, please run below command prior coming to the session
cd sydneyTestersBootcamp/02_ProvisioningTestEnvironment/machines (if you're not in the machines folder)
vagrant box add chef/ubuntu-14.04
bundle install
and select option 1 (Virtual Box), this would trigger downloading the base virtual box for ubuntu 14.04 x64
######Ruby and related Gems
- For Unix:
curl -sSL https://get.rvm.io | bash -s stable --ruby
- For Windows: download and install Ruby
- Installing require gems and vagrant plugins:
sudo gem install bundler
vagrant plugin install vagrant-berkshelf
vagrant plugin install vagrant-omnibus
vagrant plugin install vagrant-cachier
######Checkout project from GitHub
- If you don't have git, you can find it here.
git clone https://github.com/SydneyTestersBootcamp/sydneyTestersBootcamp.git
- Bring up the machine
cd sydneyTestersBootcamp/02_ProvisioningTestEnvironment/machines
bundle install
vagrant up
- You're now ready to travel to your VM
vagrant ssh
For Windows, you will need an SSH client
Port: 22
Host: 33.33.33.10 (the ip address in your Vagrantfile)
Username: vagrant
Password: vagrant
####Most used commands
- vagrant up: bring up and provision the machine
- vagrant destroy: anything goes wrong, destroy the machine and rebuild it with vagrant up
- vagrant halt: shutdown the machine
- vagrant reload: restart the machine
- vargant provision: provision the machine with all chef's recipes
- vagrant box add box-name / box-url: download the base box (this step is included in vagrant up, but we can still pre-download it)
- vagrant suspend: hibernate the machine, you can later resume it with vagrant resume
- vagrant ssh: connect to the local virtual machine via ssh
####Common issues
- RuntimeError: Couldn't determine Berks version
You would need to add chefdk/bin at front of your PATH
For MacOSX: default chefdk is at /opt/chefdk/bin
For Windows: default chefdk is at C:\opscode\chefdk\bin - The directory where plugins are installed (the Vagrant home directory) has a space in it...
For Windows user only, you can useecho %username%
to get username and you can fix this by moving the .vagrant.d to a folder that has no space in the full path, and set the system variable VAGRANT_HOME=new_path_to_vagrant.d
i.e: VAGRANT_HOME=C:\HashiCorp.vagrant.d
####Reading Material
- Mischa Taylor's Coding Blog:
Getting started writing chef cookbooks the berkshelf way
Getting started writing chef cookbooks the berkshelf way. Part 2
Getting started writing chef cookbooks the berkshelf way. Part 3