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

     2023-02-16     89

关键词:

【中文标题】自定义配置脚本 Azure 资源管理器模板【英文标题】:Custom configuration script azure resource manager template 【发布时间】:2019-12-26 20:25:19 【问题描述】:

我正在使用 ARM 模板创建一个 azure 市场报价。我正在使用我的 ARM 模板创建 Linux VM。我需要在部署后运行自定义配置脚本。我按照 azure quickstart repo 中提供的示例进行操作。

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   

, “属性”:空

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


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

【问题讨论】:

你在虚拟机资源[]中有这个吗?您将定义模板的资源[],然后您应该在其中包含 Microsoft.Compute/virtualMachines 资源[]。您的 CustomScript 应该在 VM 资源[]【参考方案1】:

错误意味着它是一个嵌套资源(配置对象嵌套在站点对象内),名称需要反映这一点。因此,名称应该类似于virtualMachines/extensions,而不是 config。我还需要添加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。

【讨论】:

自定义 Azure API 管理开发人员门户

】自定义AzureAPI管理开发人员门户【英文标题】:CustomizingtheAzureAPIManagementdeveloperportal【发布时间】:2017-09-0613:50:19【问题描述】:通过查看将AzureAPI管理开发人员门户组合在一起的模板的标记,您可以提供内联样式来调整元素的... 查看详情

unitytools-自定义脚本模板(代码片段)

资源下载链接:【传送门】自定义脚本模板用途例子效果用途在Unity引擎中Create一个C#脚本时默认创建的是继承MonoBehaviour的脚本、当我们想使用其他继承或接口以及类时还需要更改、比较麻烦、这时就可以使用自己写的自定义脚... 查看详情

如何通过 PowerShell 或 ARM 模板在 Azure 数据资源管理器中创建表和摄取映射

】如何通过PowerShell或ARM模板在Azure数据资源管理器中创建表和摄取映射【英文标题】:HowtocreateTableandIngestionMappinginAzureDataExplorerviaPowerShellorARMTemplate【发布时间】:2021-08-1614:46:34【问题描述】:我们希望自动创建和设置Azure数据... 查看详情

使用 azure ARM 模板配置逻辑应用失败警报

...则和操作组,以便在失败时发送邮件。是否可以使用Azure资源管理器模板创建这些东西?【问题讨论】:【参考方案1】:是的,这个tutorial将帮助您使用ARM模板创建警报。您可以 查看详情

通过 Azure 资源管理器 (ARM) 模板创建 SQL Server

】通过Azure资源管理器(ARM)模板创建SQLServer【英文标题】:CreateSQLServerviaAzureResourceManager(ARM)template【发布时间】:2019-01-2611:50:04【问题描述】:我正在尝试创建一个新的SQLServerAzure实例,然后我想在其中创建一些新数据库。我从Azu... 查看详情

用于本地文件的 Azure 自定义脚本扩展 CLI/Powershell

】用于本地文件的Azure自定义脚本扩展CLI/Powershell【英文标题】:AzureCustomScriptExtensionCLI/PowershellforLocalfiles【发布时间】:2020-03-0918:21:09【问题描述】:我正在尝试在VM上使用自定义脚本扩展运行脚本。我可以通过扩展设置中的UI... 查看详情

如何将 GitHub 添加到最新 API 版本的 Azure 资源管理器网站部署模板?

】如何将GitHub添加到最新API版本的Azure资源管理器网站部署模板?【英文标题】:HowdoyouaddGitHubtoanAzureResourceManagerWebSitedeploymenttemplatelatestwiththelatestAPIVersion?【发布时间】:2015-12-1916:14:59【问题描述】:他们在之前的模板中使用了... 查看详情

如何为 AVD 管理器创建自定义 Android 设备配置文件?

】如何为AVD管理器创建自定义Android设备配置文件?【英文标题】:HowcanIcreateacustomAndroidDeviceProfileforAVDmanager?【发布时间】:2020-07-2920:57:33【问题描述】:假设我的设备不是Google的Pixel设备,那么如何为我的设备创建自定义硬件配... 查看详情

TFS Api 未在 Dev Azure 上的自定义流程模板中提供自定义状态

】TFSApi未在DevAzure上的自定义流程模板中提供自定义状态【英文标题】:TFSApinotgivingcustomstatesinacustomizedProcessTemplateonDevAzure【发布时间】:2021-08-2013:09:41【问题描述】:我在Scrum流程模板中添加了一个自定义状态,但在我基于该自... 查看详情

Azure Service Fabric - 外部状态管理器

...据存储(如MongoDB或DocumentDB)中。这个想法是提供一个自定义状态管理器,它将数据存储在数据库中,而不是内存(或磁盘,或任何ASF所做的)中。 查看详情

spring启动自定义登录:“登录”,模板可能不存在,或者任何配置的模板解析器都可能无法访问

我正在尝试使用springsecurity实现自定义登录。所以我添加了maven依赖项。<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>< 查看详情

rr中的自定义评估回归模型脚本用于azure机器学习(代码片段)

查看详情

如何从 azure 存储资源管理器中读取 html 文件

】如何从azure存储资源管理器中读取html文件【英文标题】:howtoreadhtmlfilefromazurestorageexplorer【发布时间】:2021-09-0607:51:57【问题描述】:如何从Azure存储资源管理器读取.html文件。通过connectionstring可以访问blob。字符串模板=bloburl+"... 查看详情

具有 Spring Security 和 Java 配置的自定义身份验证管理器

】具有SpringSecurity和Java配置的自定义身份验证管理器【英文标题】:CustomAuthenticationManagerwithSpringSecurityandJavaConfiguration【发布时间】:2015-10-2720:36:36【问题描述】:我正在将SpringSecurity与SpringMVC一起使用来创建一个与现有应用程... 查看详情

配置 WSO2 API 管理器自定义身份验证器和声明

】配置WSO2API管理器自定义身份验证器和声明【英文标题】:configuringWSO2APImanagercustomauthenticatorandclaims【发布时间】:2015-07-2115:38:17【问题描述】:我无法通过使用WSO2API管理器1.9.0的自定义身份验证器来保留自定义声明。对于上下... 查看详情

Azure 自定义策略 - 仅适用于新资源

】Azure自定义策略-仅适用于新资源【英文标题】:AzureCustomPolicy-Applyonlytonewresources【发布时间】:2020-08-2515:07:20【问题描述】:这是我的政策:"mode":"All","policyRule":"if":"allOf":["field":"type","in":["Microsoft.Compute/virtualMachines","Microsoft.Comp... 查看详情

Azure 角色配置管理

...web.config的使用可能涉及连接字符串、应用程序设置或自定义 查看详情

14.azure流量管理器(下)

接下来开始创建流量管理器创建流量管理器配置文件在名称中,提供配置文件的名称。此名称必须在trafficmanager.cn区域中唯一,并会生成DNS名称(trafficmanager.cn),该名称用于访问流量管理器配置文件。在路由方法中,选择您需要的... 查看详情