DevOps Basics: Enabling The Puppet Virtual Machine Extension Via PowerShell

Practicing DevOps in one’s organization sometimes requires the inclusion of existing processes currently championing automation. One said solution via Puppet Lab provides a datacenter automation and configuration management solution that is widely used. While utilizing PowerShell to enable desired state configuration (DSC) can also be a viable option, some organizations may have current practices that require to stay the course on using Puppet. PowerShell can be utilized to address this need.

Puppet extensions can be enabled using the Set-AzureVMPuppetExtension Azure PowerShell cmdlet. The a parameter PuppetMasterServer  can be accepted via a cmdlet to reference the Puppet master server in a similar fashion to the management portal. Utilizing the Set-AzureVMPuppetExtension cmdlet can enable modifying the virtual machine configuration object during provisioning. The following Azure PowerShell cmdlet evokes said extension:

$puppetServer = "puppetmaster.cloudapp.net"
$imageFamily = "Windows Server 2012 R2 Datacenter"
$imageName = Get-AzureVMImage |
                where { $_.ImageFamily -eq $imageFamily } |
                           sort PublishedDate -Descending |
                 select -ExpandProperty ImageName -First 1
New-AzureVMConfig -Name $vmName `
                    -InstanceSize $size `
                    -ImageName $imageName |

Add-AzureProvisioningConfig -Windows `
                            -AdminUsername $adminUser `
                            -Password $password |
Set-AzureVMPuppetExtension -PuppetMasterServer $puppetServer |
New-AzureVM -ServiceName $serviceName `
            -Location $location

An IT professional also has the ability to run the Set-AzureVMPuppetExtension cmdlet on a provisioned virtual machine. This is completed by aquiring the virtual machine configuration with Get-AzureVM, changing it with Set-AzureVMPuppetExtension, followed by updating the configuration via the Update-AzureVM cmdlet.

$puppetServer = "puppetmaster.cloudapp.net"
Get-AzureVM -ServiceName $serviceName -Name $vmName |
Set-AzureVMPuppetExtension -PuppetMasterServer $puppetServer |
Update-AzureVM