如何在 ARM 模板中多次使用具有不同脚本 uri 的相同扩展
How to use same extension with different script uri multiple times in ARM templates
我想 运行 创建 VM 后的第一个扩展脚本。然后在部署集群后,我想 运行 在同一 VM 上使用设置中的时间戳设置第二个扩展脚本。但是我无法 运行 第二个脚本。它说错误如下
Multiple VMExtensions per handler not supported for OS type 'Linux
d
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(variables('vmName'),'/install-script')]",
"apiVersion": "[variables('computeApiVersion')]",
"location": "[variables('location')]",
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName'))]"
],
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.0",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": ["[variables('installScript')]"]
},
"protectedSettings":{
"commandToExecute": "[concat('bash config.sh', ' ', parameters('key'))]"
}
}
},
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(variables('vmName'),'/install-script1')]",
"apiVersion": "[variables('computeApiVersion')]",
"location": "[variables('location')]",
"dependsOn": [
"[resourceId(parameters('clusterResourceGroupName'), 'Microsoft.Resources/deployments', variables('clusterTemplateName'))]",
"[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName'))]"
],
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.0",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": ["[variables('installScript1')]"],
"timestamp": "123456789"
},
"protectedSettings":{
"commandToExecute": "[concat('bash config1.sh', ' ', parameters('key1'))]"
}
}
},
更新:-
我正在使用以下方法部署集群和虚拟机。我仍然得到同样的错误。我添加了 forceUpdatetag 在这种方法中我需要修改什么才能使其工作?
{
"apiVersion": "[variables('resourceDeploymentApiVersion')]",
"name": "[variables('clusterTemplateName')]",
"type": "Microsoft.Resources/deployments",
"resourceGroup": "[parameters('clusterResourceGroupName')]",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[variables('clusterTemplateURL')]"
},
"parameters": {},
}
},
{
"apiVersion": "[variables('resourceDeploymentApiVersion')]",
"name": "[variables('vmTemplateName')]",
"type": "Microsoft.Resources/deployments",
"resourceGroup": "[parameters('vmGroupName')]",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[variables('vmTemplateURL')]"
},
"parameters": {},
}
}
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(variables('vmName'),'/install-script')]",
"apiVersion": "[variables('computeApiVersion')]",
"location": "[variables('location')]",
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName'))]"
],
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.0",
"autoUpgradeMinorVersion": true,
"forceUpdateTag": "v.1.0",
"settings": {
"fileUris": ["[variables('installScript')]"]
},
"protectedSettings":{
"commandToExecute": "[concat('bash config.sh', ' ', parameters('key'))]"
}
}
},
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(variables('vmName'),'/install-script1')]",
"apiVersion": "[variables('computeApiVersion')]",
"location": "[variables('location')]",
"dependsOn": [
"[resourceId(parameters('clusterResourceGroupName'), 'Microsoft.Resources/deployments', variables('clusterTemplateName'))]",
"[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName'))]"
],
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.0",
"autoUpgradeMinorVersion": true,
"forceUpdateTag": "v.1.1",
"settings": {
"fileUris": ["[variables('installScript1')]"]
},
"protectedSettings":{
"commandToExecute": "[concat('bash config1.sh', ' ', parameters('key1'))]"
}
}
},
您可以使用嵌套部署来执行此操作。因此,您需要创建一个带有脚本扩展名的虚拟机并创建一个嵌套部署。该嵌套部署需要依赖扩展才能完成。嵌套部署将只是另一个资源 (Microsoft.Compute/virtualMachines/extensions),它必须与之前的脚本扩展同名 并且 forceUpdateTag
不同。这样就可以了。
需要此解决方法,因为 VM 只能有每种扩展类型的 1 个副本。通过这种方式,您可以使用新值更新扩展并强制其使用 forceUpdateTag
.
重新运行
工作示例:
https://paste.ee/p/4mOiI - 仅带有脚本扩展的嵌套模板
https://paste.ee/p/nG7XV - 父模板
我想 运行 创建 VM 后的第一个扩展脚本。然后在部署集群后,我想 运行 在同一 VM 上使用设置中的时间戳设置第二个扩展脚本。但是我无法 运行 第二个脚本。它说错误如下
Multiple VMExtensions per handler not supported for OS type 'Linux
d
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(variables('vmName'),'/install-script')]",
"apiVersion": "[variables('computeApiVersion')]",
"location": "[variables('location')]",
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName'))]"
],
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.0",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": ["[variables('installScript')]"]
},
"protectedSettings":{
"commandToExecute": "[concat('bash config.sh', ' ', parameters('key'))]"
}
}
},
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(variables('vmName'),'/install-script1')]",
"apiVersion": "[variables('computeApiVersion')]",
"location": "[variables('location')]",
"dependsOn": [
"[resourceId(parameters('clusterResourceGroupName'), 'Microsoft.Resources/deployments', variables('clusterTemplateName'))]",
"[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName'))]"
],
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.0",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": ["[variables('installScript1')]"],
"timestamp": "123456789"
},
"protectedSettings":{
"commandToExecute": "[concat('bash config1.sh', ' ', parameters('key1'))]"
}
}
},
更新:-
我正在使用以下方法部署集群和虚拟机。我仍然得到同样的错误。我添加了 forceUpdatetag 在这种方法中我需要修改什么才能使其工作?
{
"apiVersion": "[variables('resourceDeploymentApiVersion')]",
"name": "[variables('clusterTemplateName')]",
"type": "Microsoft.Resources/deployments",
"resourceGroup": "[parameters('clusterResourceGroupName')]",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[variables('clusterTemplateURL')]"
},
"parameters": {},
}
},
{
"apiVersion": "[variables('resourceDeploymentApiVersion')]",
"name": "[variables('vmTemplateName')]",
"type": "Microsoft.Resources/deployments",
"resourceGroup": "[parameters('vmGroupName')]",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[variables('vmTemplateURL')]"
},
"parameters": {},
}
}
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(variables('vmName'),'/install-script')]",
"apiVersion": "[variables('computeApiVersion')]",
"location": "[variables('location')]",
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName'))]"
],
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.0",
"autoUpgradeMinorVersion": true,
"forceUpdateTag": "v.1.0",
"settings": {
"fileUris": ["[variables('installScript')]"]
},
"protectedSettings":{
"commandToExecute": "[concat('bash config.sh', ' ', parameters('key'))]"
}
}
},
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(variables('vmName'),'/install-script1')]",
"apiVersion": "[variables('computeApiVersion')]",
"location": "[variables('location')]",
"dependsOn": [
"[resourceId(parameters('clusterResourceGroupName'), 'Microsoft.Resources/deployments', variables('clusterTemplateName'))]",
"[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName'))]"
],
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.0",
"autoUpgradeMinorVersion": true,
"forceUpdateTag": "v.1.1",
"settings": {
"fileUris": ["[variables('installScript1')]"]
},
"protectedSettings":{
"commandToExecute": "[concat('bash config1.sh', ' ', parameters('key1'))]"
}
}
},
您可以使用嵌套部署来执行此操作。因此,您需要创建一个带有脚本扩展名的虚拟机并创建一个嵌套部署。该嵌套部署需要依赖扩展才能完成。嵌套部署将只是另一个资源 (Microsoft.Compute/virtualMachines/extensions),它必须与之前的脚本扩展同名 并且 forceUpdateTag
不同。这样就可以了。
需要此解决方法,因为 VM 只能有每种扩展类型的 1 个副本。通过这种方式,您可以使用新值更新扩展并强制其使用 forceUpdateTag
.
工作示例:
https://paste.ee/p/4mOiI - 仅带有脚本扩展的嵌套模板
https://paste.ee/p/nG7XV - 父模板