Home Automation with VirtualBox, Vagrant & Chef
Post
Cancel

Automation with VirtualBox, Vagrant & Chef

In this article, we’re testing Chef to automated deploying virtual machines (vm)s using:

  • Chef Zero –> infrastructure code, developing in local mode.
    Follow default prompts, and download from https://www.chef.io/downloads/tools/workstation the application is open-source that provides template deployment for OS.

  • Vagrant –> VM template manager.
    Follow default prompts, and download from https://www.vagrantup.com/downloads the application allows you to deploy VMs using CLI in a consistent manner By default vagrant box images are stored in the ./vagrant directory

  • VirtualBox –> software hypervisor.
    Follow default prompts, download from https://www.virtualbox.org/wiki/Downloads is a software-defined hypervisor for creating virtual machines.

Prepping the compute element

1. If using Windows operating system, disable Hyper-V

Disable Hyper-V with PowerShell, having different hypervisor software installed will cause issues.

1
    Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All

2. Test vagrant application functionality

On a linux instance run sudo /sbin/vboxconfig from the command line an ensure all checks are cleared.

  1. Testing Vagrant Application
    • Run vagrant commands to ensure the application is installed correctly.
  2. Start/Initialize the Project
    • Navigate to the project folder and initialize a vagrant config file vagrant.exe init hashicorp bionic64 note bionic64 is a maintained custom image of Ubuntu by hashicorp.
  3. Start the vagrant VM installation
  4. Destroy the vagrant instance
    • Run vagrant.exe destroy this will destroy the vagrant vm instance.


Testing VM Automation with Chef Zero

1. Create a Chef project folder

  • I recommend creating the subfolder within the same project directory for easy management/reference. It can get confusing as the build progress with new files and folders. Hence take the time to plan out the folder structure for the project.
    1
    
      mkdir /home/userA/Desktop/chef_myproj
    

2. Initialize a Chef cookbook (a.k.a template)

  • Navigate to the project folder and use chef generate cookbook
    1
    2
    
    cd /home/userA/Desktop/chef_myproj
    chef generate cookbook chef_myproj_cookbook
    

Tip chef_myproj_cookbook is the subfolder where all the configuration files for Chef will be saved in.

3. Test build using kitchen cli

  • Run kitchen list to test deployable vagrant vm instances.

Note: Code deployment for Ubuntu64, requires an internet connection to download the packages & it’s dependencies.

This post is licensed under CC BY 4.0 by the author.