自定义配置脚本azure资源管理器模板

时间:2019-12-26 20:25:19

标签: azure azure-resource-manager azure-marketplace

我正在使用ARM模板创建一个天蓝色的市场报价。我正在使用我的AR​​M模板创建Linux VM。我需要在部署后运行自定义配置脚本。我遵循了Azure快速入门仓库中提供的示例。

https://github.com/Azure/azure-quickstart-templates/tree/master/100-marketplace-sample 当我尝试验证模板时,出现以下错误。

{   "error": {
    "additionalInfo": [
      {
        "info": {
          "lineNumber": 166,
          "linePosition": 28,
          "path": "resources[1].type"
        },
        "type": "TemplateViolation"
      }
    ],
    "code": "InvalidTemplate",
    "details": null,
    "message": "Deployment template validation failed: 'The template resource 'configScript' at line '166' and column '28' is not valid. The type property is invalid. Please see https://aka.ms/arm-template/#resources for usage details.'.",
    "target": null   

},
“属性”:null }

我模板的脚本部分看起来像

{
    "type": "extensions",
    "name": "configScript",
    "apiVersion": "2018-04-01",
    "location": "[parameters('location')]",
    "dependsOn": [
    "[parameters('vmName')]"
    ],
    "properties": {
    "publisher": "Microsoft.Azure.Extensions",
    "type": "CustomScript",
    "typeHandlerVersion": "2.0",
    "autoUpgradeMinorVersion": true,
    "settings": {
        "fileUris": [
        "[uri(parameters('_artifactsLocation'), concat('scripts/copyfilefromazure.sh', parameters('_artifactsLocationSasToken')))]"
        ]
    },
    "protectedSettings": {
        "commandToExecute": "[concat('bash ', variables('scriptFileName'), ' ', variables('scriptArgs'))]"
    }
    }
},

1 个答案:

答案 0 :(得分:0)

该错误表示它是一个嵌套资源(配置对象嵌套在站点对象内部),名称需要体现这一点。因此,名称应类似于virtualMachines/extensions,而不是配置。我还需要添加dependsOn部分。

"dependsOn": ["[concat('Microsoft.Compute/virtualMachines/', concat(variables('vmName'),copyindex()))]"]

以下是成功验证的模板:

{
  "name": "config-app",
  "type": "Extensions",
  "location": "[resourceGroup().location]",
  "apiVersion": "2019-03-01",
  "dependsOn": [
    "[concat('Microsoft.Compute/virtualMachines/', concat(variables('vmName'),copyindex()))]"
  ],
  "tags": {
    "displayName": "config-app"
  },
  "properties": {
    "publisher": "Microsoft.Azure.Extensions",
    "type": "CustomScript",
    "typeHandlerVersion": "2.0",
    "autoUpgradeMinorVersion": true,
    "settings": {
      "skipDos2Unix":false,
      "timestamp":123456789          
    },
    "protectedSettings": {
       "commandToExecute": "<command-to-execute>",
       "script": "<base64-script-to-execute>",
       "storageAccountName": "<storage-account-name>",
       "storageAccountKey": "<storage-account-key>",
       "fileUris": ["https://.."]  
    }
  }
}

有关更多详细信息,您可以阅读本文Use the Azure Custom Script Extension Version 2 with Linux virtual machines