Configure a VM with Desired State Configuration
Prerequisites
- Create an Azure Automation Account
- Create a Linux virtual machine in the Azure portal
Enable a virtual machine
- In the Azure portal, navigate to Automation accounts.
- From the list of Automation accounts, select an account.
- From 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 reported isÂ
Connecting
.
Import modules
- From 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.
Import the configuration
- 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" } } } }
- 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.
Compile a 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.
Assign a node 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 toÂPending
. 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
View node status
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.
Tag:Azure