简体   繁体   English

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

[英]Custom configuration script azure resource manager template

I am creating an azure marketplace offer using ARM template.我正在使用 ARM 模板创建一个 azure 市场报价。 I am creating a Linux VM using my ARM template.我正在使用我的 ARM 模板创建 Linux VM。 I need to run a custom configuration script post deploy.我需要在部署后运行自定义配置脚本。 I followed the example provided in the azure quickstart repo.我遵循了 azure quickstart repo 中提供的示例。

https://github.com/Azure/azure-quickstart-templates/tree/master/100-marketplace-sample When I try to validate the template i get the following error. 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   

}, },
"properties": null } “属性”:null }

The script part of my template looks like我模板的脚本部分看起来像

{
    "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'))]"
    }
    }
},

The error means that it is a nested resource (the config object is nested inside the site object) the name needs to reflect this.错误意味着它是一个嵌套资源(配置对象嵌套在站点对象内),名称需要反映这一点。 So instead of config the name should be something like virtualMachines/extensions .因此,名称应该类似于virtualMachines/extensions而不是 config 。 I also needed to add the dependsOn section.我还需要添加dependsOn部分。

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

Here's the template that validated successfully:这是验证成功的模板:

{
  "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://.."]  
    }
  }
}

For more details, you could read this article Use the Azure Custom Script Extension Version 2 with Linux virtual machines .有关更多详细信息,您可以阅读本文将 Azure 自定义脚本扩展版本 2 用于 Linux 虚拟机

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM