Home > Blogs > VMware PowerCLI Blog > Tag Archives: DSC

Tag Archives: DSC

New Release – DSC Resources for VMware 2.0

The Desired State Configuration (DSC) Resources for VMware was released late last year. This initial release was able to leverage the PowerShell DSC engine in order to declare configurations for a handful of ESXi host settings and a couple vCenter server settings. The response to these resources has been amazing! So amazing that over the last 7 months, there have been 64 issues and 74 pull requests. A result of all of that feedback, input, and code contributions brings us to the next release, version 2.0 of the DSC Resources for VMware!

The DSC Resources for VMware version 2.0 contains a number of new resources, lots of improvements, and a new way to access them. First and foremost, as requested, these resources are now available on the PowerShell Gallery! There are also a number of examples which have been added to the repository since the first release. In the root of the repo, there’s an ‘Examples’ folder which contains some examples of combining multiple resources into a single configuration. Then, within the resource itself, there’s a folder by the name of ‘Configurations’. This folder has example configurations of using these resources with configuration management utilities like Ansible, Chef, and Puppet. Lastly, there are 14 new resources for us to use!

Let’s walk through some of the new resources.

New Resources

These newly added resources can be easily categorized into the following buckets: Inventory, vSphere Standard Switch (vSS), and VMHost.

The new Inventory resources, which allow us to manage the existence of these object types, are:

  • Cluster
  • HACluster
  • DRSCluster
  • DatacenterFolder
  • Datacenter
  • Folder

The following is an example of using the Folder resource to manage a VM based folder, named Management, along with a folder nested in the first folder:

The new vSS resources, which allow us to manage a VMHost’s vSS configuration, are:

  • VMHostVss
  • VMHostVssBridge
  • VMHostVssSecurity
  • VMHostVssShaping
  • VMHostVssTeaming

The following is an example of using the VMHostVss resource to manage a vSS on a particular VMHost:

The new VMHost resources, which have been added to the already existing set of resources that manage VMHosts, are:

  • VMHostService
  • VMHostSettings
  • VMHostSyslog
  • VMHostAccount

The following is an example of using the VMHostService resource to manage an ESXi host’s SSH service to ensure it is running and the policy is set to automatic:

Here’s a demo which combines a number of the new resources for the following configuration:
Datacenter: DemoLab
Folder Structures:
Development
- Linux
- Windows
Management
- Linux
- Windows
- VMware
Production
- Linux
- Windows

PowerCLI DSC v2 Resources Demo

Summary

The DSC Resources for VMware have only been available for a short period of time, however they have made a tremendous impact! Over the last 7 months, there have been 64 issues and 74 pull requests to the GitHub repository. Today, we’re taking the culmination of that input and releasing the 2.0 version of these resources. This adds an additional 14 resources, a number of functionality improvements, and they have been added to the PowerShell Gallery!

I also want to say a special thank you to some of our community contributors: Luc Dekens, for his immense contributions to this release including having a hand in at least 8 of the new resources as well as Brett Johnson and Markus Fischbacher for their contributions as well!

To get started, it is now as simple to install as:

Demo: DSC Resource Installation

For more information on this release, see the latest release page on the DSC Resources for VMware GitHub page.

Let us know in the comments how you’re using these in your environment and what resources you’re looking for next!

Getting Started with Desired State Configuration Resources for VMware

Today, we are happy to announce a brand-new and open-sourced way to manage your vSphere environment. The Desired State Configuration (DSC) Resources for VMware allows partners, automation engineers, DevOps teams, and system administrators a new way to apply standard configuration management processes through PowerShell DSC and PowerCLI!

Let’s take a walk through how we can get started using these DSC resources and apply our first configuration!

Desired State Configuration Resources for VMware Overview

PowerShell DSC has been out for a while, since Windows Server 2012 R2 as a matter of fact. To summarize in a single sentence: PowerShell DSC can manage and monitor a system’s configuration based on what’s known as configuration files, which happen to be written as PowerShell code. This is all made possible thanks to the Local Configuration Manager (LCM). LCM is the “engine” running locally on each of the target nodes that takes the configuration file, interprets it, and applies all the configured parts. These parts include a system’s configuration, in what manner the configuration is refreshed, and how often it is refreshed, just to name a few.

The above is important because the DSC Resources for VMware operate a little differently than a standard DSC configuration. The DSC Resources for VMware make use of a proxy LCM host. This is because the LCM cannot run on the VCSA (both vCenter and PSC based appliances) nor can it run on ESXi hosts. An important note about this proxy LCM host, it has to be Windows PowerShell based. Furthermore, only PowerShell 5.1 and PowerCLI 10.1.1 or newer will be supported.

Desired State Configuration Resources for VMware

This first release of the DSC Resources for VMware will be able to manage a couple different areas for both vCenter and ESXi hosts. They are as follows:

  • vCenterStatistics
    • Level
    • PeriodLength
  • vCenterSettings
    • EventMaxAge
    • TaskMaxAge
    • Logging Level
  • VMHostNtpSettings
    • NTP Server
    • NTPD Service Policy
  • VMHostDnsSettings
    • HostName
    • DomainName
    • Address
  • VMHostSatpClaimRule
    • RuleName
    • Transport
    • Description
  • VMHostTpsSettings
    • ShareScanTime
    • ShareForceSalting

Installation Overview

We now know what it is and what it can do, how about the installation? On the designated proxy LCM system, we will want to download the module from GitHub and make it available in one of our designated PSModulePath directories. The zip file is available through the following link: Desired State Configuration Resources for VMware

Here’s some code that can streamline the download and initialization process:

After we have installed the module we should be able to list the newly acquired module and import it into our active PowerShell Session:

Example: Importing the VMware.vSphereDSC Module

We can also verify the DSC resources we have available:

Example: Output of available DSC Resources

Next, we need to make sure the proxy LCM system can understand the DSC configuration files. This is done through the Windows Remote Management service. We can setup the WinRM service or verify that the WinRM service is setup with the following code:

In my environment, this system already had WinRM setup so I received the following message:
Example: Windows Remote Management Configuration

We should now be all set to start setting up DSC resources in our environment!

Managing an ESXi Host’s NTP

The DSC Resources for VMware repository has some pre-created configuration files which can be sourced to create the MOF file. The MOF file, which stands for Managed Object Format, is the output from a configuration file which has been compiled by the LCM. These configuration files are located in the repo at the following location: \Source\VMware.vSphereDSC\Configurations In my environment, I’ve created my own fork of the repository and cloned it to my local system where I’ll be referencing the files.

In our example, we’re going to setup DSC to manage an ESXi host’s NTP configuration. We can see some parameters and some settings by opening the VMHostNtpSettings_Config.ps1 file that’s located in the ESXiConfigs directory.

Input Type Input Name Input Description
Parameter Name Resource Name
Server Server Host Name
User ESXi host username
Password ESXi host password
Setting NtpServer NTP server/s the host will use
NtpServicePolicy Status for the NTPD service

For my lab environment, I’m going to update the NtpServer values and accept the service policy setting of ‘automatic’. I’m also going to apply this configuration at the ESXi host level, so my host name and server name will match.

We can do this with the following commands:

As part of the output, we should see the following MOF file having been created:
Example: Configuring and creating MOF file

We can then test the MOF file against our host with the following command:

Added to the output, I have also included another PowerShell session which is polling the host for the current NTP server/s and service policy:
Example: Pre-DSC Configuration

In the above example, notice the ‘InDesiredState’ property with a value of False.

Now, we’re ready to start applying our configuration. We do this with the following command:

After a few moments, we’re ready to check the current DSC configuration with the following command:

Again, I’ve added a second PowerShell session to show the current status of the host:
Example: Post DSC Configuration Status

For reference, this is the code I’m running to show the current status of the host’s NTP configuration:

In some later blog posts, we’ll take a look at some of the other areas of this module including applying configurations to multiple hosts, applying vCenter settings, applying values to multiple hosts in a vCenter, and some ways to apply better security practices to both the credentials and the MOF.

Summary

PowerCLI is back with a brand-new feature, Desired State Configuration Resources for VMware! These resources allow PowerCLI to make use of PowerShell DSC to define the configuration of a desired node. The DSC Resources for VMware can define ESXi host settings such as NTP servers, DNS servers, and TPS share scan times. We can also define vCenter settings such as statistics level and logging level. As an additional benefit, these resources are also open-source and community contributions are absolutely welcome!

Check out the Desired State Configuration Resources for VMware on GitHub and let us know what you’re looking forward to using DSC on most in your vSphere environment!