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- ./vagrantdirectory
- 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.
- Testing Vagrant Application- Run vagrant commands to ensure the application is installed correctly.
 
- Start/Initialize the Project- Navigate to the project folder and initialize a vagrant config file vagrant.exe init hashicorp bionic64note bionic64 is a maintained custom image of Ubuntu by hashicorp.
 
- Navigate to the project folder and initialize a vagrant config file 
- Start the vagrant VM installation- Run vagrant.exe upthis will initiate the build process, it will look for the vagrant version of ubuntu if not available it will download from the Vagrant Cloud https://app.vagrantup.com/ubuntu/boxes/bionic64
 
- Run 
- Destroy the vagrant instance- Run vagrant.exe destroythis will destroy the vagrant vm instance.
 
- Run 
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 cookbook1 2 cd /home/userA/Desktop/chef_myproj chef generate cookbook chef_myproj_cookbook
Tip
chef_myproj_cookbookis the subfolder where all the configuration files for Chef will be saved in.
3. Test build using kitchen cli
- Run kitchen listto test deployable vagrant vm instances.
Note: Code deployment for Ubuntu64, requires an internet connection to download the packages & it’s dependencies.
