Thursday, March 10, 2022

Azure Series - Virtual Machines - Desired State Configuration - Create and Use

 This article provides a step-by-step guide for doing the most common tasks with Azure Automation State Configuration, such as creating, importing, and compiling configurations, enabling machines to manage, and viewing reports.

Prerequisites

  1. An Azure Automation account
  2. An Azure Resource Manager VM (not Classic) running a supported operating system.

Step 1 : Create DSC Configuration

  1. Start VSCode.
  2. Type following text:
configuration MyTestConfig
{
    Node IsWebServer
    {
        WindowsFeature IIS
        {
            Ensure               = 'Present'
            Name                 = 'Web-Server'
            IncludeAllSubFeature = $true
        }
    }

    Node NotWebServer
    {
        WindowsFeature IIS
        {
            Ensure               = 'Absent'
            Name                 = 'Web-Server'
        }
    }
}
  1. Save the file as MyTestConfig.ps1.

Step 2: Import configuration into Azure Automation.

  1. Browse to Azure Portal, Automation Account Page.
  2. select State configuration (DSC) under Configuration Management
  3. On the State configuration (DSC) page, click the Configurations tab, then click Add
  4. Specify the configuration file created in step 1 and give appropriate name.

Step 3: Compile a configuration in Azure Automation

  1. Browse to Azure Portal, Automation Account Page.
  2. select State configuration (DSC) under Configuration Management
  3. On the State configuration (DSC) page, click the Configurations tab, then click Configuration created in step 2.
  4. Then click compile button to start compiling.

Step 4: Enable an ARM VM for management with State Configuration

  1. Browse to Azure Portal, Automation Account Page.
  2. select State configuration (DSC) under Configuration Management
  3. On the State configuration (DSC) page, select the Nodes tab, then click Add.
  4. On the Virtual Machines pane, select your VM.
  5. On the Virtual machine detail pane, click + Connect.
  6. On the Registration page, select the name of the node configuration to apply to the VM in the Node configuration name field.
    Note: Drop down will display all nodes from the file created in step 1.
  7. Check Reboot Node if Needed, then click OK.

The node configuration you specified is applied to the VM at intervals specified by the value provided for Configuration Mode Frequency. The VM checks for updates to the node configuration at intervals specified by the Refresh Frequency value.

Step 5: View manage nodes reports

  1. Browse to Azure Portal, Automation Account Page.
  2. select State configuration (DSC) under Configuration Management
  3. On the State configuration (DSC) page, select the Nodes tab.
  4. click the node record to open the reporting.

No comments: