The vSphere DSC – Just another perspective

In the last couple of weeks, I have done rounds of meeting with our customers and discussed ways to automate ESXi build and configuration. The most common piece which I found in each of the environment was vSphere auto-deploy. Today, most of our customers deploy ESXi hosts using auto-deploy and post configuration tasks via host profiles. Majority of question or concerns which I got were related to the host profile. My understanding says that customers tend to find host profiles difficult to understand, which is not the case in reality.

Host profiles are excellent. It’s just you need to fine-tune them initially. You rarely get any issue if you have cracked the host profiles successfully. The key here is to set up a reference host and extracting the host profile from it.

Having said that, let me bring you another perspective on doing the post configuration tasks. Today many of you love to do Infrastructure as a Code and believe in a configuration management ecosystem. When you look around all the configuration management tools, you will find that vSphere Desired State Configuration (DSC) is very close to being a complete solution for vSphere configuration management.

vSphere DSC is an open-source module that provides PowerShell DSC resources for VMware. PowerShell DSC resources follow declarative code style, like most configuration management tools, and allow you to document infrastructure configurations. The module has 71 resources that cover most of the configuration aspects of vSphere infrastructure.

We shouldn’t be looking at vSphere DSC in isolation and rather look at complimenting it with vSphere auto-deploy. Think about this, PXE boot ESXi hosts from vSphere auto-deploy and let vSphere DSC do all the post configurations for you, isn’t that cool!

When you extract the host profile, you get all the configurations of an ESXi host, and at times you need to trim down the configurations to ensure that you have control over it. 

vSphere DSC is just the opposite of this approach. You can start with an empty configuration file and keep adding the resource definitions to it as and when required. vSphere DSC configuration gives a complete picture of configurations that you want to Ensure and allows you to quickly replicate the same in other environments.

Just take a look at the below snippet and a demo of my Lab configuration which does range of things on vCenter and ESXi host.

$vmhostlist=@('10.196.113.64','10.196.113.65')
Configuration NodeDSC {
Import-DscResource -ModuleName VMware.vSphereDSC
vSphereNode 'HBTVCSA01.cpbu.com' {
        #vCenter Configuration -----------------------------------------
        HACluster HACluster {                       #Create HA Cluster
            Ensure = 'Present'
            Location = [string]::Empty
            DatacenterName = 'HBT'
            DatacenterLocation = [string]::Empty
            Name= 'DSCDemo'
            HAEnabled = $true
            HAAdmissionControlEnabled = $true
            HAFailoverLevel = 1
            HAIsolationResponse = 'DoNothing'
            HARestartPriority = 'Low'

        }

        DRSCluster DRSCluster                        #Create DRS Cluster
        {
            Ensure = 'Present'
            Location = [string]::Empty
            DatacenterName = 'HBT'
            DatacenterLocation = [string]::Empty
            Name= 'DSCDemo'
            DRSEnabled = $true
            DrsAutomationLevel = 'FullyAutomated'
            DrsMigrationThreshold = 5
        }

                                                                #create a new vDSwitch
        VDSwitch VDSwitch {
            Name = 'HBT-DSC-dvSwitch'
            Location = 'DSCdvSwitch'
            DatacenterName = 'HBT'
            DatacenterLocation = ''
            Ensure = 'Present'
            ContactDetails = 'jprohit@vmware.com'
            ContactName = 'Jatin Purohit'
            LinkDiscoveryProtocol = 'CDP'
            LinkDiscoveryProtocolOperation = 'Advertise'
            Mtu = 1500
            Notes = 'My Notes for Distributed Switch'
            NumUplinkPorts = 2
            Version = '6.6.0'
        }

       

        #ESXi Configuration Start here------------------------------
        Foreach($vmhost in $vmhostlist)
        {

            vCenterVMHost $vmhost {                            #Move host to DSCDemo Cluster
                Name = $vmhost
                Location = 'DSCDemo'
                DatacenterName = 'HBT'
                DatacenterLocation = ''
                Ensure = 'Present'
                VMHostCredential = $hostCredential
                Port = 443
                Force = $true
                DependsOn = '[DRSCluster]DRSCluster'
            }

            VMHostVssMigration $vmhost {                        #Configure vmnic0 and vmnic1 as the vSwitch Uplink
                VMHostName = $vmhost
                VssName = 'vSwitch0'
                PhysicalNicNames = @('vmnic0', 'vmnic1')
            }

            VMHostVDSwitchMigration $vmhost {
                VMHostName = $vmhost
                VdsName = 'HBT-DSC-dvSwitch'
                PhysicalNicNames = @('vmnic2', 'vmnic3')
                MigratePhysicalNicsOnly = $true
            }
            $NFSRSName01= $vmhost+'_HBTDS01'                     #Add NFS Datastore HBTDSC01
            NfsDatastore $NFSRSName01 {
                VMHostName = $vmhost
                Name = 'HBTDS01'
                Path = '/HBTDS01'
                Ensure = 'Present'
                NfsHost = '10.196.113.8'
                FileSystemVersion = '3'
                AccessMode = 'ReadWrite'
                AuthenticationMethod = 'AUTH_SYS'
                StorageIOControlEnabled = $true
                CongestionThresholdMillisecond = 10
            }
            
            $vmhostCoredmp=$vmhost+'_vmkdmp'
            VMHostNetworkCoreDump $vmhostCoredmp {
                Name = $vmhost
                Enable = $true
                InterfaceName = 'vmk0'
                ServerIp = '10.196.113.60'
                ServerPort = 6500
            }

        }   
    }
}    

Concluding this, I would say that vSphere DSC just opens up another way of automating the infrastructure builds and config. The project has come a long way now and has done significant improvements in terms of resource coverage.

Stay tuned with the vSphere DSC project and soon you will get new updates from the VMware PowerCLI team.

Learn More about vSphere DSC: https://github.com/vmware/dscr-for-vmware/wiki



One response to “The vSphere DSC – Just another perspective”

  1. […] View Reddit by jatinpurohit92 – View Source […]

Leave a Reply

%d bloggers like this: