AZ-400: Designing and Implementing Microsoft DevOps Solutions

Design and Implement Infrastructure as Code IaC

Azure Automation State Configuration

In this lesson, we explore Azure Automation Desired State Configuration (DSC)—a robust Azure service designed to automate and manage system configurations across both Azure and on-premises environments. By leveraging specialized PowerShell scripts, DSC verifies current settings, deploys updates, and enforces new configurations to ensure system compliance.

Azure Automation DSC delivers three primary functions:

  1. It verifies the current system setup.
  2. It updates configurations as needed.
  3. It deploys new configurations across multiple systems concurrently.

This level of automation not only saves time but also reduces the risk of human error compared to manual configuration methods.

The image illustrates the Azure Automation State Configuration process in three steps: automating checking, updating, and deployment configuration.

Key Features

Azure Automation DSC offers significant benefits that include:

FeatureDescription
Centralized ManagementManage configurations for all your systems from one unified interface.
Automatic Correction of Configuration DriftAutomatically restores system settings to the desired state if deviations occur.
Detailed Compliance ReportingGenerate comprehensive reports to track compliance across your infrastructure.

Note

For more detailed information on Azure Automation DSC, refer to the official Azure documentation.

Managing Multiple Virtual Machines

Consider a scenario where you need to ensure that specific software is installed and configured across multiple Windows virtual machines (VMs). By combining Azure Automation DSC with Azure Virtual Machines, you can seamlessly manage and monitor configurations across your entire environment.

The image is an example of Azure Automation State Configuration, detailing a scenario of managing configurations for multiple VMs, with the objective of ensuring specific software is installed on Windows VMs, using Azure Automation and Azure VMs.

Step 1: Create an Automation Account

Begin by creating an Automation Account in Azure, which acts as your central control hub for managing configurations and running automated tasks.

The image shows a Microsoft Azure interface for creating an automation account, with a highlighted button to "Create automation account." It indicates no existing automation accounts are displayed.

Step 2: Connect Virtual Machines

After creating your automation account, the next step is to connect your VMs. This process integrates your existing Azure VMs with the automation account, allowing DSC to manage settings and enforce periodic configuration checks. You can customize the frequency of these checks and updates to suit your operational needs.

The image shows a screenshot of the Azure Automation State Configuration interface, highlighting the "State configuration (DSC)" section with options for managing nodes and configurations. It includes a navigation menu on the left and a status overview on the right.

The image shows a screenshot of the Microsoft Azure portal, specifically the Azure Automation State Configuration section, with a virtual machine named "vm-sre-dev-001" that is running but not connected.

Once you confirm the settings, Azure proceeds to connect your VM to the automation account.

The image shows a screenshot of the Azure Automation State Configuration interface, specifically the registration settings for configuring DSC (Desired State Configuration) for a virtual machine. It includes fields for registration key, node configuration name, refresh frequency, and other configuration options.

After a successful connection, your VM appears in the DSC dashboard’s status section, displaying its compliance state.

The image shows a screenshot of the Azure portal, specifically the Azure Automation State Configuration page, displaying details of a virtual machine named "vm-sre-dev-001" with its status and registration information.

Adding and Applying a New Configuration

Now that your VM is connected, you can add a new configuration. You have the option to write your own DSC script or utilize one from the gallery. In this example, we will use a script that sets up a daily task on the VM. This task runs a PowerShell process every day at midnight and repeats every 15 minutes for an 8-hour period.

The image shows a screenshot of the Azure Automation State Configuration interface, specifically focusing on adding a DSC (Desired State Configuration) from the gallery. It highlights the "TestAutomationAccount" and options for managing configurations.

Importing and Compiling the Configuration

Once the configuration is imported into your automation account, compile it to verify for errors and prepare it for deployment. Below is an example DSC configuration script:

Node localhost
{
    ScheduledTask ScheduledTaskDailyAdd
    {
        TaskName         = 'Test task Daily'
        TaskPath         = 'MyTasks'
        ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
        ScheduleType     = 'Daily'
        DaysInterval     = 1
        RepeatInterval   = '00:15:00'
    }
}

After compiling, note that your previously compliant VM will temporarily register as non-compliant because the new configuration has not yet been applied.

The image shows a screenshot of the Azure Automation State Configuration interface, highlighting the "Compile" option for a specific configuration. It includes details like resource group, location, and subscription information.

Applying the Configuration to Your VM

To deploy the new configuration:

  1. Open the VM's page within your automation account.
  2. Select "Assign Node Configuration."
  3. Choose the desired configuration and confirm your selection.

The image shows an example of Azure Automation State Configuration, specifically the "Assign Node Configuration" interface, with a list of resources and services on the left sidebar.

Following this assignment, the VM will initially be marked as non-compliant while it applies the new settings. Once the configuration process completes successfully, the VM’s status will update to compliant. This demonstrates how Azure Automation DSC helps maintain consistency and enforces the desired configuration across your infrastructure.

Warning

Ensure that your DSC configurations are thoroughly tested in a staging environment before rolling them out to production systems to prevent any disruptive changes.

Through this lesson, you have learned how to effectively utilize Azure Automation DSC to manage multiple virtual machines, reducing configuration drift and automating system updates to maintain optimal performance and compliance.

Watch Video

Watch video content

Previous
Design and implement desired state configuration for environments