The following documents the setup steps for building a sane workstation environment to write and test Chef code. This document should work with Mac OS X, Windows, or Linux nodes.
A workstation is a computer running the Chef Development Kit (ChefDK) that is used to author cookbooks, interact with the Chef server, and interact with nodes
You will need to install the following software on your system:
- Chef Development Kit (ChefDK) - The Chef Development Kit contains all of the tools you need to write and test Chef code
- Vagrant - Vagrant is a tool for building complete development environments
- VirtualBox - Free open source tool for launching virtual machines on your laptop
- A Developers text editor like Atom, Sublime Text, or other
Open a terminal and run the following commands
$ chef -v - should return the version of ChefDK you have installed
$ vagrant -v - should return the version of vagrant you have installed
$ VBoxManage -v should return the version of VirtualBox installed
$ chef -v
Chef Development Kit Version: 2.2.1
chef-client version: 13.3.42
delivery version: master (73ebb72a6c42b3d2ff5370c476be800fee7e5427)
berks version: 6.3.1
kitchen version: 1.17.0
inspec version: 1.35.1
$
$
$ vagrant -v
Vagrant 1.9.1
$
$
$ VBoxManage -v
5.1.14r112924
Chef installs the Ruby programming language separate from any existing installs of Ruby. In this step we will setup your shell environment to use that version of ruby:
- Open a terminal
- Run the command
echo 'eval "$(chef shell-init bash)"' >> ~/.bashrc* - Relaunch terminal or run the command
source ~/.bashrc - Run the command
which rubyshould return/opt/chefdk/embedded/bin/ruby
- NOTE: If you are running another shell
shorzshyou can substitute the name of your shell for bash
In this step we will download a Vagrant box image for testing with Virutual Box.
- Open a terminal (bash, powershell, etc)
- Run the following command
vagrant box add bento/centos-6.8 - When prompted choose Option 2 'virtualbox'
$ vagrant box add bento/centos-6.8
==> box: Loading metadata for box 'bento/centos-6.8'
box: URL: https://atlas.hashicorp.com/bento/centos-6.8
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.
1) parallels
2) virtualbox
3) vmware_desktop
Enter your choice: 2
==> box: Adding box 'bento/centos-6.8' (v2.3.1) for provider: virtualbox
box: Downloading: https://atlas.hashicorp.com/bento/boxes/centos-6.8/versions/2.3.1/providers/virtualbox.box
If you would rather use a Windows Base box for testing you will need an account at Vagrant Cloud. Once logged in you can run the following commands...
$ vagrant login
In a moment we will ask for your username and password to HashiCorp's
Atlas. After authenticating, we will store an access token locally on
disk. Your login details will be transmitted over a secure connection, and
are never stored on disk locally.
If you do not have an Atlas account, sign up at
https://atlas.hashicorp.com.
Atlas URL: https://app.vagrantup.com
Atlas Username: sford@chef.io
Password (will be hidden):
You are now logged in.
$ vagrant box add opentable/win-2012r2-standard-amd64-nocm
==> box: Loading metadata for box 'opentable/win-2012r2-standard-amd64-nocm'
box: URL: https://app.vagrantup.com/opentable/win-2012r2-standard-amd64-nocm
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.
1) virtualbox
2) vmware_desktop
Enter your choice: 1
==> box: Adding box 'opentable/win-2012r2-standard-amd64-nocm' (v1.0.0) for provider: virtualbox