title | description | services | ms.subservice | keywords | ms.date | ms.topic | ms.custom |
---|---|---|---|---|---|---|---|
Azure Quickstart - Configure a VM with Desired State Configuration | Microsoft Docs |
This article helps you get started configuring a VM with Desired State Configuration. |
automation |
dsc |
dsc, configuration, automation |
11/06/2018 |
quickstart |
mvc |
By enabling Azure Automation State Configuration, you can manage and monitor the configurations of your Windows and Linux servers using Desired State Configuration (DSC). Configurations that drift from a desired configuration can be identified or auto-corrected. This quickstart steps through enabling a Linux VM and deploying a LAMP stack using Azure Automation State Configuration.
To complete this quickstart, you need:
- An Azure subscription. If you don't have an Azure subscription, create a free account.
- An Azure Automation account. For instructions on creating an Azure Automation Run As account, see Azure Run As Account.
- An Azure Resource Manager VM (not classic) running Red Hat Enterprise Linux, CentOS, or Oracle Linux. For instructions on creating a VM, see Create your first Linux virtual machine in the Azure portal
Sign in to Azure at https://portal.azure.com.
There are many different methods to enable a machine for State Configuration feature. This quickstart tells how to enable the feature for a VM using an Automation account. You can learn more about different methods to enable your machines for State Configuration by reading Enable machines for management by Azure Automation State Configuration.
- In the left pane of the Azure portal, select Automation accounts. If it is not visible in the left pane, click All services and search in the resulting view.
- In the list, select an Automation account.
- In the left pane of the Automation account, select State configuration (DSC).
- Click Add to open the VM select page.
- Find the virtual machine for which to enable DSC. You can use the search field and filter options to find a specific virtual machine.
- Click on the virtual machine, and then click Connect
- Select the DSC settings appropriate for the virtual machine. If you have already prepared a configuration, you can specify it as
Node Configuration Name
. You can set the configuration mode to control the configuration behavior for the machine. - Click OK. While the DSC extension is deployed to the virtual machine, the status shows up as
Connecting
.
Modules contain DSC resources and many can be found in the PowerShell Gallery. Any resources that are used in your configurations must be imported to the Automation account before compiling. For this tutorial, the module named nx is required.
- In the left pane of the Automation account, select Modules Gallery under Shared Resources.
- Search for the module to import by typing part of its name:
nx
. - Click on the module to import.
- Click Import.
This quickstart uses a DSC configuration that configures Apache HTTP Server, MySQL, and PHP on the machine. See DSC configurations.
In a text editor, type the following and save it locally as AMPServer.ps1.
configuration LAMPServer {
Import-DSCResource -module "nx"
Node localhost {
$requiredPackages = @("httpd","mod_ssl","php","php-mysql","mariadb","mariadb-server")
$enabledServices = @("httpd","mariadb")
#Ensure packages are installed
ForEach ($package in $requiredPackages){
nxPackage $Package{
Ensure = "Present"
Name = $Package
PackageManager = "yum"
}
}
#Ensure daemons are enabled
ForEach ($service in $enabledServices){
nxService $service{
Enabled = $true
Name = $service
Controller = "SystemD"
State = "running"
}
}
}
}
To import the configuration:
- In the left pane of the Automation account, select State configuration (DSC) and then click the Configurations tab.
- Click + Add.
- Select the configuration file that you saved in the prior step.
- Click OK.
You must compile a DSC configuration to a node configuration (MOF document) before it can be assigned to a node. Compilation validates the configuration and allows for the input of parameter values. To learn more about compiling a configuration, see Compiling configurations in State Configuration.
- In the left pane of the Automation account, select State Configuration (DSC) and then click the Configurations tab.
- Select the configuration
LAMPServer
. - From the menu options, select Compile and then click Yes.
- In the Configuration view, you see a new compilation job queued. When the job has completed successfully, you are ready to move on to the next step. If there are any failures, you can click on the compilation job for details.
You can assign a compiled node configuration to a DSC node. Assignment applies the configuration to the machine and monitors or auto-corrects for any drift from that configuration.
- In the left pane of the Automation account, select State Configuration (DSC) and then click the Nodes tab.
- Select the node to which to assign a configuration.
- Click Assign Node Configuration
- Select the node configuration
LAMPServer.localhost
and click OK. State Configuration now assigns the compiled configuration to the node, and the node status changes toPending
. On the next periodic check, the node retrieves the configuration, applies it, and reports status. It can take up to 30 minutes for the node to retrieve the configuration, depending on the node settings. - To force an immediate check, you can run the following command locally on the Linux virtual machine:
sudo /opt/microsoft/dsc/Scripts/PerformRequiredConfigurationChecks.py
You can view the status of all State Configuration-managed nodes in your Automation account. The information is displayed by choosing State Configuration (DSC) and clicking the Nodes tab. You can filter the display by status, node configuration, or name search.
In this quickstart, you enabled a Linux VM for State Configuration, created a configuration for a LAMP stack, and deployed the configuration to the VM. To learn how you can use Azure Automation State Configuration to enable continuous deployment, continue to the article:
[!div class="nextstepaction"] Set up continuous deployment with Chocolatey