Swift Software Group

Ubuntu and Chef with Vagrant and VirtualBox on Windows

In this post we show how you can use VirtualBox and Vagrant to launch an Ubuntu 14.04 guest and install the latest Chef client on it using Windows 10 as a host.

Prerequisites

You need VirtualBox and Vagrant installed. To do that, you can follow the steps described in Ubuntu with Vagrant and VirtualBox on Windows.

Chef

Install Chef Development Kit (ChefDK)

In PowerShell as Administrator:

choco install chefdk

Install Chef on the guest

Before you can use Chef Solo, Chef Zero, or Chef Client for provisioning, you need to install the latest Chef client on the guest.

Open Vagrantfile and add the following code at the end of the configuration:

# Provision Chef Client with a shell script that runs the Chef Omnibus Installer
# For more information see https://docs.chef.io/install_omnibus.html
# 
config.vm.provision "shell", inline: <<-SHELL
  sudo apt-get update -y
  sudo apt-get install curl -y
  curl -L https://www.opscode.com/chef/install.sh | sudo bash
SHELL

The complete Vagrantfile file should look like this:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
#
Vagrant.configure(2) do |config|

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  #
  config.vm.box = "ubuntu/trusty64"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  #
  config.vm.provider "virtualbox" do |vb|
    # For a complete reference, please see the online documentation at
    # https://docs.vagrantup.com/v2/virtualbox/configuration.html

    # Name used in Oracle VM VirtualBox Manager GUI
    vb.name = "Ubuntu-x64-Vagrant"

    # Customize the amount of memory on the VM (in MB):
    vb.memory = "2048"

    # Customize the amount of video memory on the VM (in MB):
    vb.customize ["modifyvm", :id, "--vram", "128"]
  end

  # Provision Chef Client with a shell script that runs the Chef Omnibus Installer
  # For more information see https://docs.chef.io/install_omnibus.html
  # 
  config.vm.provision "shell", inline: <<-SHELL
    sudo apt-get update -y
    sudo apt-get install curl -y
    curl -L https://www.opscode.com/chef/install.sh | sudo bash
  SHELL
end

Test

Reload and provision the guest virtual machine. This should install the latest Chef Client:

vagrant reload
vagrant provision