gpt4 book ai didi

自定义脚本失败的 Azure ARM

转载 作者:行者123 更新时间:2023-12-03 00:51:21 26 4
gpt4 key购买 nike

我的arm模板中有以下代码片段,用于在虚拟机上运行自定义脚本

"variables": {
"installES": "https://sentiencescripts.blob.core.windows.net/script/elasticsearch-centos-install.sh"
},


"resources": [
{
"type": "extensions",
"name": "installelasticsearch",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines', concat(variables('vmName'), copyindex(1)))]"
],
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.0",
"settings": {
"fileUris": "[variables('installES')]",
"protectedSettings": {
"commandToExecute": "sh elasticsearch-centos-install.sh",
"storageAccountName": "myaccount",
"storageAccountKey": "my-key"
}

}
}
}
]

由于以下错误而失败

New-AzureRmResourceGroupDeployment : 6:23:31 PM - Resource Microsoft.Compute/virtualMachines 'es-master-node1' failed with message '{
"status": "Failed",
"error": {
"code": "ResourceDeploymentFailure",
"message": "The resource operation completed with terminal provisioning state 'Failed'.",
"details": [
{
"code": "VMExtensionProvisioningError",
"message": "VM has reported a failure when processing extension 'installelasticsearch'. Error message: \"Enable failed: failed to get configuration: json validation error:
invalid public settings JSON: fileUris: Invalid type. Expected: array, given: string\"."
}
]
}
}'
At line:1 char:1

更新 1:我更新了"fileUris": ["[variables('installES')]"], ,根据@Francois

但仍然出现以下错误

New-AzureRmResourceGroupDeployment : 8:13:37 AM - Resource Microsoft.Compute/virtualMachines 'es-master-node2' failed with message '{
"status": "Failed",
"error": {
"code": "ResourceDeploymentFailure",
"message": "The resource operation completed with terminal provisioning state 'Failed'.",
"details": [
{
"code": "VMExtensionProvisioningError",
"message": "VM has reported a failure when processing extension 'installelasticsearch'. Error message: \"Enable failed: failed to get configuration: json validation error:
invalid public settings JSON: protectedSettings: Additional property protectedSettings is not allowed\"."
}
]
}
}'

然后我替换

"protectedSettings": {
"commandToExecute": "sh elasticsearch-centos-install.sh",
"storageAccountName": "myaccount",
"storageAccountKey": "my-key"
}

"commandToExecute": "sh elasticsearch-centos-install.sh"

但仍然出现同样的错误。

更新2:

将我的模板修改为以下内容后

{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(variables('vmName'), copyindex(1),'/', variables('extensionName'))]",
"apiVersion": "[variables('apiVersion')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', variables('vmName'), copyindex(1))]"
],
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.0",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": "[split(parameters('fileUris'), ' ')]",
"commandToExecute": "[parameters('commandToExecute')]"
},
"protectedSettings": {
"storageAccountName": "[parameters('customScriptStorageAccountName')]",
"storageAccountKey": "[parameters('customScriptStorageAccountKey')]"
}
}
}

它适用于单个虚拟机,但不适用于多个虚拟机。

New-AzureRmResourceGroupDeployment : 3:35:59 PM - Error: Code=InvalidTemplate; Message=Deployment template validation failed: 
'The template resource '[concat(variables('vmName'), copyindex(1),'/', variables('extensionName'))]' at line '158' and column '10' is not valid:
The template function 'copyIndex' is not expected at this location. The function can only be used in a resource with copy specified. Please see https://aka.ms/arm-copy for usage details..'.
At line:1 char:1
+ New-AzureRmResourceGroupDeployment -Name ElasticSearch -ResourceGroup ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

New-AzureRmResourceGroupDeployment : The deployment validation failed
At line:1 char:1
+ New-AzureRmResourceGroupDeployment -Name ElasticSearch -ResourceGroup ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureRmResourceGroupDeployment], InvalidOperationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

谁知道 copyindex() Microsoft.Compute/virtualMachines/extensions 受支持

最佳答案

设法使以下 block 正常工作

{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(variables('vmName'),copyindex(1),'/', variables('extensionName'))]",
"apiVersion": "[variables('apiVersion')]",
"location": "[resourceGroup().location]",
"copy": {
"name": "virtualMachineInstallationLoop",
"count": "[variables('vmInstances')]"
},
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', variables('vmName'),copyindex(1))]"
],
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.0",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": "[split(parameters('fileUris'), ' ')]",
"commandToExecute": "[parameters('commandToExecute')]"
},
"protectedSettings": {
"storageAccountName": "[parameters('customScriptStorageAccountName')]",
"storageAccountKey": "[parameters('customScriptStorageAccountKey')]"
}
}
}

关于自定义脚本失败的 Azure ARM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39401270/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com