Azure ARM-DSC VM配置

问题描述 投票:0回答:1

我想使用ARM模板和DSC配置我的VM。我使用powershell命令创建的.zip文件在powershell中准备了简单的DCS脚本。提到的.zip文件已上传到存储帐户容器。现在,我想使用此.zip文件在ARM模板下方的测试VM上进行配置更改。我收到错误消息New-AzResourceGroupDeployment : 10:12:09 AM - VM has reported a failure when processing extension 'dscExtension'. Error message: "The DSC Extension failed to execute: Error downloading https://storageAccountName.blob.core.windows.net/containerName/test.zip after 2 attempts: <?xml version="1.0" encoding="utf-8"?><Error><Code>ResourceNotFound</Code><Message>The specified resource does not exist.

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "vmName": {
            "type": "string",
            "minLength": 1,
            "metadata": {
                "description": "List of virtual machines to be reconfigured, if using multiple VMs, make their names comma separate. E.g. VM01, VM02, VM03."
            },
            "defaultValue": "VM1,VM2"
        },
        "Location": {
            "type": "string",
            "metadata": {
                "description": "Location of the VM"
            },
            "defaultvalue": "WestEurope"
        },
        "functionName": {
            "type": "string",
            "metadata": {
                "description": "Specify the function name"
            },
            "defaultvalue": "test.ps1\\testConfigurationName"
        },
        "storageAccountName": {
            "type": "string",
            "metadata": {
                "description": "Specify the Storage Account name, Storage Account where DCS .zip module is located"
            }
        },
        "setupScriptContainerName": {
            "type": "string",
            "metadata": {
                "description": "Specify the Storage Account container name, container where DCS .zip module is located"
            }
        },
        "DSCSetupArchiveFileName": {
            "type": "string",
            "metadata": {
                "description": "Specify the Storage Account container name, container where DCS .zip module is located"
            },
            "defaultvalue": "test.zip"
        },
        "nodeConfigurationName": {
            "type": "string",
            "metadata": {
                "description": "The name of the node configuration, on the Azure Automation DSC pull server, that this node will be configured as"
            },
            "defaultValue": "testConfigurationName.localhost"
        },
        "registrationKey": {
            "type": "securestring",
            "metadata": {
                "description": "Registration key to use to onboard to the Azure Automation DSC pull/reporting server"
            },
            "defaultValue": "AutomationAccountPrimaryKey"
        },
        "registrationUrl": {
            "type": "string",
            "metadata": {
                "description": "Registration url of the Azure Automation DSC pull/reporting server"
            },
            "defaultValue": AutomationAccountRegistrationURL"
        }
    },
    "variables": {
        "vmListArray": "[split(parameters('vmName'),',')]"
    },
    "resources": [
        {
            "type": "Microsoft.Compute/virtualMachines/extensions",
            "apiVersion": "2015-06-15",
            "name": "[concat(trim(variables('vmListArray')[copyIndex()]),'/dscExtension')]",
            "copy": {
                "name": "ExtentionLooptoAllVMs",
                "count": "[length(variables('vmListArray'))]"
            },
            "location": "[parameters('Location')]",
            "properties": {
                "autoUpgradeMinorVersion": true,
                "publisher": "Microsoft.Powershell",
                "type": "DSC",
                "typeHandlerVersion": "2.19",
                "protectedSettings": {
                    "Items": {
                        "registrationKeyPrivate": "[parameters('registrationKey')]"
                    }
                },
                "settings": {
                    "ModulesUrl": "[concat('https://',parameters('storageAccountName'),'.blob.core.windows.net/',parameters('setupScriptContainerName'),'/',parameters('DSCSetupArchiveFileName'))]",
                    "ConfigurationFunction": "[parameters('functionName')]",
                    "Properties": [
                        {
                            "Name": "RegistrationKey",
                            "Value": {
                                "UserName": "PLACEHOLDER_DONOTUSE",
                                "Password": "PrivateSettingsRef:registrationKeyPrivate"
                            },
                            "TypeName": "System.Management.Automation.PSCredential"
                        },
                        {
                            "Name": "RegistrationUrl",
                            "Value": "[parameters('registrationUrl')]",
                            "TypeName": "System.String"
                        },
                        {
                            "Name": "NodeConfigurationName",
                            "Value": "[parameters('nodeConfigurationName')]",
                            "TypeName": "System.String"
                        }
                    ]
                }
            }
        }
    ]
}

更新版本:

"resources": [
      {
          "type": "Microsoft.Compute/virtualMachines/extensions",
          "apiVersion": "2018-10-01",
          "name": "[concat(trim(variables('vmListArray')[copyIndex()]),'/dscExtension')]",
          "copy": {
              "name": "ExtentionLooptoAllVMs",
              "count": "[length(variables('vmListArray'))]"
          },
          "location": "[parameters('Location')]",
          "properties": {
              "autoUpgradeMinorVersion": true,
              "publisher": "Microsoft.Powershell",
              "type": "DSC",
              "typeHandlerVersion": "2.9",
              "protectedSettings": {
                  "Items": {
                      "registrationKeyPrivate": "[parameters('registrationKey')]"
                  }
              },
              "settings": {
                  "configuration": {
                      "url": "[concat('https://',parameters('storageAccountName'),'.blob.core.windows.net/',parameters('setupScriptContainerName'),'/',parameters('DSCSetupArchiveFileName'))]",
                      "script": "[parameters('scriptName')]",
                      "function": "[parameters('functionName')]"
                  },
                  "Properties": [
                      {
                          "Name": "RegistrationKey",
                          "Value": {
                              "UserName": "PLACEHOLDER_DONOTUSE",
                              "Password": "PrivateSettingsRef:registrationKeyPrivate"
                          },
                          "TypeName": "System.Management.Automation.PSCredential"
                      },
                      {
                          "Name": "RegistrationUrl",
                          "Value": "[parameters('registrationUrl')]",
                          "TypeName": "System.String"
                      },
                      {
                          "Name": "NodeConfigurationName",
                          "Value": "[parameters('nodeConfigurationName')]",
                          "TypeName": "System.String"
                      },
                      {
                          "Name": "ConfigurationMode",
                          "Value": "[parameters('configurationMode')]",
                          "TypeName": "System.String"
                      },
                      {
                          "Name": "ConfigurationModeFrequencyMins",
                          "Value": "[parameters('configurationModeFrequencyMins')]",
                          "TypeName": "System.Int32"
                      },
                      {
                          "Name": "RefreshFrequencyMins",
                          "Value": "[parameters('refreshFrequencyMins')]",
                          "TypeName": "System.Int32"
                      },
                      {
                          "Name": "RebootNodeIfNeeded",
                          "Value": "[parameters('rebootNodeIfNeeded')]",
                          "TypeName": "System.Boolean"
                      },
                      {
                          "Name": "ActionAfterReboot",
                          "Value": "[parameters('actionAfterReboot')]",
                          "TypeName": "System.String"
                      },
                      {
                          "Name": "AllowModuleOverwrite",
                          "Value": "[parameters('allowModuleOverwrite')]",
                          "TypeName": "System.Boolean"
                      }
                  ]
              }
          }
      }
  ]
azure-resource-manager azure-powershell azure-automation dsc
1个回答
0
投票

根据错误,您无法从所使用的Azure blob存储帐户下载zip文件。请为Blob或set the blob access level to Public创建一个sas令牌。

例如

Public

有关更多详细信息,请参阅 "resources": [ { "type": "Microsoft.Compute/virtualMachines/extensions", "name": "[concat(parameters('vmName'),'/Microsoft.Powershell.DSC')]", "apiVersion": "2015-06-15", "location": "[parameters('location')]", "properties": { "publisher": "Microsoft.Powershell", "type": "DSC", "typeHandlerVersion": "2.19", "autoUpgradeMinorVersion": true, "protectedSettings": { "Items": { "registrationKeyPrivate": "[parameters('registrationKey')]" } }, "settings": { "ModulesUrl": "<the url of you azure blob>", "SasToken": "<the sas token for the blob>", "ConfigurationFunction": "[parameters('configurationFunction')]", ... } ] document

© www.soinside.com 2019 - 2024. All rights reserved.