Using vCloud Air to stand-up a Chef Compliance Proof-of-Concept

20151211 - 1The other day I wanted to start playing with Chef, as it’s a tool our company is about to use a lot, and it’s one area I’m quite behind the curve on. Unfortunately the lab was maxed out for resources, so I decided to turn to vCloud Air to rapidly provision an environment.

I’ve not really done much with my vCloud Air On-Demand subscription since using it as an endpoint for vRealize Automation, so it felt good to get back into it. Unfortunately due to other projects I didn’t have a lot of time to mess about with the web UI, so turned to PowerCLI to get me up and running fast.

A lot of vCloud Air commands were introduced in PowerCLI 6.0 Release 2 (at the time of writing release 3 is available), so you need to update to that to realise the full benefits. Check out Alan Renouf’s blog article at http://www.virtu-al.net/2015/09/17/powercli-6-0-r2-the-most-advanced-version-vmware-has-ever-made for more information.

For the proof-of-concept I ideally want three boxes – the compliance server and two test boxes (one Windows and one Linux).

I have already built a Windows VM and assigned one of my TechNet licences, and then exported it to OVF. I could use ovftool to import it, but PowerCLI has an easier way of achieving the same thing.

The two remaining Linux boxes can be provisioned on vCloud Air directly.

Getting started

First we need to store our vCloud Air credentials:

$credential = Get-Credential

Next we need to select the region our vCloud Air instance is based. Some popular choices are:

  • us-ca
  • us-vi
  • uk-sl
  • au-so
  • de-ge

My region is Germany:

$region = "de-ge" 
$regionstar = $region + "*"

Next we need to connect to vCloud Air:

# Connect to vCloud Air
Connect-PIServer -vCA -credential $credential -WarningAction 0 -ErrorAction 0

# Connect to compute instance
Get-PIComputeInstance -Region $regionstar | Connect-PIComputeInstance -WarningAction 0 -ErrorAction 0

Now we need to define our organization. Once connected use the following cmdlet:

Get-OrgVdc

I only have one defined:

20151215 - 1

Use the following to retrieve the catalog you want to upload your OVF to:

Get-Catalog

I have a few defined, and will use default-catalog:

$myOrgVdc = "virtualhobbitDC"
$myCatalog = "default-catalog"

Upload the OVF:

$ovf = "C:\win2012r2.ovf"
$ovfName = "Windows Server 2012 R2"
Import-CIVAppTemplate -SourcePath $ovf -Name $ovfName -OrgVdc $myOrgVdc -Catalog $myCatalog

Depending on how fast your connection is, that could take a while.

Create the vApp:

$vApp = "chef-poc"
$NewvApp = New-CIVApp -Name $vApp -OrgvDC $myOrgVdc

Next we need to get the ID for the default-routed-network. Use the following (thanks to Alan Renouf for this one) and assign the network to the vApp:

$myOrgNetwork = "default-routed-network"
$myOrgNetworkConsistent = Get-OrgNetwork -Id (Search-Cloud -QueryType OrgVdcNetwork -Filter "VdcName==$myOrgVdc;Name==$myOrgNetwork").Id
$NewVAppNetwork = New-CIVAppNetwork -VApp $vApp -Direct -ParentOrgNetwork $myOrgNetworkConsistent

A word of warning on the above. If it errors out, check you don’t have a space in your OrgDC name.

Create the CentOS virtual machines:

ForEach ($Name in $boxes){	
	New-CIVM -Name $name -vApp $vApp -VMTemplate $myTemplate -Confirm:$false
}

Configure the IP pool:

Get-CIVM | Get-CINetworkAdapter | Set-CINetworkAdapter -IPAddressAllocationMode Pool -VAppNetwork $NewVAppNetwork -Connected:$true

Start the VMs:

Start-CIVApp -VApp $NewvApp

They should now be up and running. Some time later the Windows VM will arrive 🙂

List the VMs:

Get-CIVM | Format-Table

Finally, disconnect from vCloud Air:

Disconnect-PIServer -Confirm:$false

In a follow-up post I will show how to connect to these machines and install Chef Compliance 0.9.6 in preparation for remediating the two VMs.

The full PowerCLI script is deployToVCA.ps1, which you can download from my GitHub repo:

# Variables

$credential = Get-Credential
$region = "de-ge" 
$regionstar = $region + "*"
$ovf = "C:\win2012r2.ovf"
$ovfName = "Windows Server 2012 R2"
$myOrgVdc = "virtualhobbitDC"
$myCatalog = "default-catalog"
$vApp = "chef-poc"
$myOrgNetwork = "default-routed-network"
$myTemplate = "CentOS64-64BIT"
$boxes = @("chef-compliance","chef-test")

# Connect to vCloud Air
Connect-PIServer -vCA -credential $credential -WarningAction 0 -ErrorAction 0

# Connect to compute instance
Get-PIComputeInstance -Region $regionstar | Connect-PIComputeInstance -WarningAction 0 -ErrorAction 0

# Import the Windows Server 2012 R2 OVF
Import-CIVAppTemplate -SourcePath $ovf -Name $ovfName -OrgVdc $myOrgVdc -Catalog $myCatalog

# Create the vApp
$NewvApp = New-CIVApp -Name $vApp -OrgvDC $myOrgVdc 

# Assign the network to the vApp
$myOrgNetworkConsistent = Get-OrgNetwork -Id (Search-Cloud -QueryType OrgVdcNetwork -Filter "VdcName==$myOrgVdc;Name==$myOrgNetwork").Id
$NewVAppNetwork = New-CIVAppNetwork -VApp $vApp -Direct -ParentOrgNetwork $myOrgNetworkConsistent

ForEach ($Name in $boxes){	
	
	# Create CentOS virtual machines
	New-CIVM -Name $name -vApp $vApp -VMTemplate $myTemplate -Confirm:$false
	
}

# Configure the IP pool
Get-CIVM | Get-CINetworkAdapter | Set-CINetworkAdapter -IPAddressAllocationMode Pool -VAppNetwork $NewVAppNetwork -Connected:$true  	

# Start the VMs
Start-CIVApp -VApp $NewvApp

# List all VMs
Get-CIVM | Format-Table 

# Disconnect from vCloud Air
Disconnect-PIServer -Confirm:$false

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.