Azure ARM DSC scale set deployment - cannot locate

2019-06-14 02:09发布

问题:

I am trying to deploy Virtual Machine Scale Set to Azure using ARM Template and Desired State Configuration (DSC). I have created DSC configuraiton and validated it on a separate VM that it is working. In ARM template I have following definition of DSC extension:

{
    "name": "Microsoft.Powershell.DSC",
    "properties": {
      "publisher": "Microsoft.Powershell",
      "type": "DSC",
      "typeHandlerVersion": "2.9",
      "autoUpgradeMinorVersion": true,
      "settings": {
        "configuration": {
          "url": "publicstoragebloburi/DSC/DSC.zip",
          "script": "Main.ps1",
          "function": "Main"
        },
        "configurationArguments": {
          "MachineName": "localhost",
          "WebDeployPackagePath": PublicStorageBlobPath_App.zip",
          "UserName": "[parameters('adminUsername')]",
          "Password": "[parameters('adminPassword')]",
          "AppName": "FileScanApp",
          "AppPath": "C:\\inetpub\\dev\\MyWebApp"

        }
  }

Main.ps1 file and also Configratuion with name Main do exist. Main.ps1 is located in the root directory of the ZIP Archive. When the extension is running on the VM, it is trying to locate Main.ps1 file in following directory: C:\Packages\Plugins\Microsoft.Powershell.DSC\2.71.1.0\bin..\DSCWork\DSC.1\Main.ps1 , but when I remoted to the machine the Main.ps1 is not present in the folder and I am getting following error:

{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details.","details":[{"code":"Conflict","message":"{\r\n \"status\": \"Failed\",\r\n \"error\": {\r\n \"code\": \"ResourceDeploymentFailure\",\r\n \"message\": \"The resource operation completed with terminal provisioning state 'Failed'.\",\r\n \"details\": [\r\n {\r\n \"code\": \"VMExtensionProvisioningError\",\r\n \"message\": \"VM has reported a failure when processing extension 'Microsoft.Powershell.DSC'. Error message: \\"The DSC Extension received an incorrect input: An error occurred while executing script or module 'Main.ps1': The term 'C:\\Packages\\Plugins\\Microsoft.Powershell.DSC\\2.71.1.0\\bin\\..\\DSCWork\\DSC.1\\Main.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again..\nPlease correct the input and retry executing the extension.\\".\"\r\n }\r\n ]\r\n }\r\n}"}]}

Please can somebody tell me, what am I doing wrong? I was following the way, this is implemented within the official sample ARM templates available on github. Thank you!

回答1:

As per my comment I was experiencing the same problem check your DSC.zip file. My zip file was /DSC/script.ps1. It should be /script.ps1

This is why it couldn't find the file for me.



回答2:

The url property in the configuration object needs to be a url that's accessible on the internet. The zip file is downloaded to that location on the VM and run from there. Where it's stored on the VM isn't something the template needs to know, but it does need to know where to find it on the internet.

Here is a sample that shows how to make it work end to end: https://github.com/Azure/azure-quickstart-templates/blob/master/201-vm-win-iis-app-ssl/azuredeploy.json

(there are a few others too)