Reputation: 859
Is it possible to apply multiple DSC configurations to one vm through Azure Resource Manager?
Currently I am using something like this:
{
"apiVersion": "2015-06-15",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', variables('vm_name'))]"
],
"location": "[resourceGroup().location]",
"name": "DSCSetup",
"properties": {
"publisher": "Microsoft.Powershell",
"type": "DSC",
"typeHandlerVersion": "2.20",
"autoUpgradeMinorVersion": true,
"settings": {
"modulesUrl": "[concat('https://', variables('sa_name'), '.blob.core.windows.net/.../dsc.ps1.zip')]",
"configurationFunction": "dsc.ps1\\Main",
"properties": {
"MachineName": "[variables('vm_name')]",
"UserName": "[parameters('vm_user')]"
}
},
"protectedSettings": {}
},
"type": "extensions"
}
If not, can you merge multiple DSCs automatically?
Scenario is:
Upvotes: 1
Views: 1048
Reputation: 2988
There are some approaches to this, one simple and useful that I use is Nested Configurations to mix all DSC configurations to a single one.
You are creating Configurations without any specific node. Then create Configurations with nodes that group needed configurations.
This simple example may serve as a guide about what I'm talking about. See [MS doc]]1 for more details.
Configuration WindowsUpdate
{
Import-DscResource -ModuleName PSDesiredStateConfiguration
Service ModulesInstaller {
Name = "TrustedInstaller"
DisplayName = "Windows Modules Installer"
StartupType = "Disabled"
State = "Stopped"
}
}
Configuration ServerManager
{
Import-DscResource -ModuleName PSDesiredStateConfiguration
Registry DoNotOpenServerManagerAtLogon {
Ensure = "Present"
Key = "HKLM:\SOFTWARE\Microsoft\ServerManager"
ValueName = "DoNotOpenServerManagerAtLogon"
ValueData = 1
DependsOn = "[Registry]NoAutoUpdate"
}
}
Configuration VMConfig
{
Node localhost
{
WindowsUpdate NestedConfig1 {}
ServerManager NestedConfig2 {}
}
}
With this approach it is easy for me on each DSC extension to call for the machine entry Configuration that is just a composition of the configuration I want to apply.
"publisher": "Microsoft.Powershell",
"type": "DSC",
"typeHandlerVersion": "2.20",
"configuration": {
"url": "[concat(parameters('_artifactsLocation'), '/Configuration.zip')]",
"script": "Configuration.ps1",
"function": "VMConfig"
}
Another approach will be to execute multiple ARM DSC extensions to the same machine. The trick here is to use the same name always as only one DSC extension can be executed.
The caveat with this approach is that the previous configuration on the machine is overwritten. From the functional perspective the result may be the same but if you want the DSC local manager to correct wrong configuration it will be possible only for the latest one.
Upvotes: 3
Reputation: 8717
DSC only allows for a single configuration at the moment, so if you deployed 2 DSC extensions to the same VM (I'm not sure it will actually work) the second config would overwrite the first.
You could probably stack DSC and CustomScript but since DSC can run script, I'm not sure why you'd ever need to do that...
What's your scenario?
Upvotes: 1