问题
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:
- Have multiple DSCs
- One DSC for IIS + ASP.Net
- One DSC to create Site1
- Another DSC to create Site2
- In Dev deploy Site1 and Site2 to one machine
- In Production deploy to seperate machines, maybe even in Availability Sets ...
- (Be prepared to use seperate containers in the future)
回答1:
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?
回答2:
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": "FrontEndVM"
}
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.
来源:https://stackoverflow.com/questions/40633012/apply-multiple-dscs-through-azure-resource-manager