Skip to main content

Vagrant using Hyper-V

I have been looking at learning puppet for a while now and to try it out, wanted to quickly deploy a puppet master & node (Ubuntu) on top of my Hyper-V host.

Below are the quick & easy steps I followed mostly for my own reference (n00b alert) :


  1. Enable Hyper-V on the node, this goes without saying :) (reboot after this step).
    001
    002
    003
    004
    #region enable Hyper-V                                                                        
    Add-WindowsFeature -Name Hyper-V -IncludeAllSubFeature -IncludeManagementTools
    #endregion
  2. Install Vagrant using chocolatey.
    001
    002
    003
    004
    005
    #region install vagrant
    Import-Module PackageManagement                                                               
    Install-Package -name vagrant -force -ForceBootstrap
    #endregion
  3. Now in order to use Hyper-V as the underlying hypervisor for Vagrant, earlier we had to install the Hyper-V provider...not anymore. Vagrant supports Hyper-V out of the box as one of the providers. One has to just create the below environment variable to set the default provider as Hyper-V.

    001
    002
    003
    #region set Hyper-V as the default provider for Vagrant
    [Environment]::SetEnvironmentVariable("VAGRANT_DEFAULT_PROVIDER", "hyperv", "Machine")        
    #endregion
  4. Now I created a folder named UbuntuPuppetMaster under VMs folder in my documents directory. I also created an empty file called 'vagrantfile'.

    001
    002
    003
    004
    #region create a directory & file for the Ubuntu (Puppet master) node.
    mkdir C:\Users\Administrator\Documents\VMs\UbuntuPuppetMaster
    New-Item -Path C:\Users\Administrator\Documents\VMs\UbuntuPuppetMaster\vagrantfile -ItemType File
    #endregion
  5. Here comes the power of vagrant to provision VMs, I have to just copy-paste the below content to the vagrantfile created in above step. The vagrantfile is the source of truth for the VM which will be provisioned in next step and you could do lots of stuff here while the VM is being provisioned. Read here more

    001
    002
    003
    004
    005
    006
    007
    008
    009
    010
    011
    012
    013
    VAGRANTFILE_API_VERSION = "2"
    Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
      config.vm.box = "ericmann/trusty64"
      config.vm.provider "hyperv" do |hv|
          hv.ip_address_timeout = 240
          hv.vmname = "Puppetmaster"
          hv.memory = 4096
      end
      config.vm.define "puppetmaster" do |puppetmaster|
        puppetmaster.vm.hostname = "puppetmaster"
        puppetmaster.vm.network "private_network", type: "dhcp"                                  
      end
    end
  6. Now this does not get any simpler, you have to drop into the directory where you have the vagrantfile located in PowerShell and just issue 'vagrant up', it will take care of downloading the vagrant box and provisioning the changes on top of the box.

Note- Vagrant at the moment can't configure networking for Hyper-V provider.

It does not get any simpler than this, now this is a very short post on how to use Vagrant with Hyper-V and there are lot many things you could do with Vagrant, and I would recommend exploring more of it.

Popular posts from this blog

Test connectivity via a specific network interface

Recently while working on a Private cloud implementation, I came across a scenario where I needed to test connectivity of a node to the AD/DNS via multiple network adapters.  Many of us would know that having multiple network routes is usually done to take care of redundancy. So that if a network adapter goes down, one can use the other network interface to reach out to the node. In order to make it easy for everyone to follow along, below is an analogy for the above scenario: My laptop has multiple network adapters (say Wi-Fi and Ethernet) connected to the same network. Now how do I test connectivity to a Server on the network only over say Wi-Fi network adapter?

PowerShell + SCCM : Run CM cmdlets remotely

Today I saw a tweet about using implicit remoting to load the Configuration Manager on my machine by Justin Mathews . It caught my eye as I have never really tried it, but theoretically it can be done. Note - The second tweet says "Cannot find a provider with the name CMSite", resolution to which is in the Troubleshooting section at the end.

PowerShell : Trust network share to load modules & ps1

Problem Do you have a central network share, where you store all the scripts or PowerShell modules ? What happens if you try to run the script from a network share ? or if you have scripts (local) which invoke scripts or import PowerShell modules stored on this network share ? Well you would see a security warning like below (Note - I have set execution policy as 'Unrestricted' not 'bypass' here): Run a .ps1 from the network share Well this is a similar warning, which you get when you download scripts from Internet. As the message says run Unblock-File cmdlet to unblock the script and then run it, let's try it.