Install MMA Agent to Azure VM Scale Set Machines Using Azure DSC

Recently one of my customers had a requirement to install and configure Microsoft Monitoring Agent (MMA) on all machines of VM Scale Set to collect application data to Log Analytics Workspace. They are using several Scale Sets and several machines in each Scale Set and they need a solution to support new instances that are added to Scale Set due to auto scaling.

So, I decided to deploy Azure DSC extension to the VM Scale Set with a DSC configuration to download and install MMA Agent. Since the Scale Set is behind a load balancer, they have an internal proxy to reach out to internet. The same will be used as Proxy for MMA Agent to connect to internet as well.

I thought, I would write down the steps for others looking for similar solution.

Step 1: Create DSC Configuration

Copy Below script to Notepad and save it as MMAgent.ps1. Set WS Id, WS Key and Proxy URL accordingly.

Configuration MMAgent
{
    $OIPackageLocalPath = "C:\Deploy\MMASetup-AMD64.exe"
    $OPSINSIGHTS_WS_ID = "OPSINSIGHTS_WS_ID"
    $OPSINSIGHTS_WS_KEY = "OPSINSIGHTS_WS_KEY"
    $INTERNET_PROXY_URL = "INTERNET_PROXY"
    $OPINSIGHTS_PROXY_URL = "INTERNET_PROXY" #Internet Proxy or Log Analytics Gateway

    Import-DscResource -ModuleName xPSDesiredStateConfiguration
    Import-DscResource -ModuleName PSDesiredStateConfiguration

    Node localhost {
                  Service OIService
                  {
                                 Name = "HealthService"
                                 State = "Running"
                                 DependsOn = "[Package]OI"
                  }

                  xRemoteFile OIPackage {
                                 Uri = "https://go.microsoft.com/fwlink/?LinkId=828603"
                                 DestinationPath = $OIPackageLocalPath
								 Proxy = $INTERNET_PROXY_URL
                  }

                  Package OI {
                                 Ensure = "Present"
                                 Path  = $OIPackageLocalPath
                                 Name = "Microsoft Monitoring Agent"
                                 ProductId = "3CC28940-B587-4B46-9F18-9927D6F13202"
                                 Arguments = Arguments = '/C:"setup.exe /qn NOAPM=1 ADD_OPINSIGHTS_WORKSPACE=1 OPINSIGHTS_WORKSPACE_ID=' + $OPSINSIGHTS_WS_ID + ' OPINSIGHTS_WORKSPACE_KEY=' + $OPSINSIGHTS_WS_KEY + ' OPINSIGHTS_PROXY_URL=' + $OPINSIGHTS_PROXY_URL + ' AcceptEndUserLicenseAgreement=1"'
                                 DependsOn = "[xRemoteFile]OIPackage"
                  }
    }
}

Step 2: Install the Dependency Modules

In the system where you are going to create DSC Configuration, install the dependency modules. In our scenario, it is xPSDesiredStateConfiguration. Run below command in PS Window (needless to say, as Administrator)

Install-Module -Name xPSDesiredStateConfiguration

Follow the on-screen instructions and install the module.

Step 3: Create DSC Configuration

The Publish-AzVMDscConfiguration cmdlet takes in a configuration file, scans it for dependent DSC resources, and then creates a .zip file. The .zip file contains the configuration and DSC resources that are needed to enact the configuration. The cmdlet can also create the package locally by using the -OutputArchivePath parameter.

Execute below command in PS Window. Change PS1 path and ZIP file path as per need.

Publish-AzVMDscConfiguration ".\MMAgent.ps1" -OutputArchivePath ".\MMAgent.ps1.zip"

Step 4: Install and Configure DSC Extension for VM Scale Set

Once the configuration is ready, Login to Azure Portal and navigate to VM Scale Set. Navigate to Extensions Section and click Add. Choose “Powershell Desired State Configuration” and click Create.

  1. Browse the ZIP file for Configuration Modules or Script -> Browse the ZIP file you have created in Step 3.
  2. Module-qualified Name of Configuration -> Give ScriptName\ConfigurationName format. (as per script in step 1, it should be MMAgent.ps1\MMAgent)
  3. Configuration Arguments -> Leave Empty
  4. Configuration Data PSD1 File -> Leave Empty
  5. WMF Version -> Leave it as latest
  6. Data Collection -> Set to Disable
  7. Version -> 2.76.
  8. Auto Upgrade Minor Version -> Set to Yes
  9. Click OK

The extension will be installed in all running VMs in Scale Set. When deallocated VMs are started or new VMs are added (Scale Out), the extensions will get installed automatically and data will be sent to Log Analytics Workspace through the proxy.

You may also like...

Leave a Reply

%d bloggers like this: