我的arm模板中有以下代码片段,用于在VM上运行自定义脚本
"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: 我根据@Francois
更新了"fileUris": ["[variables('installES')]"],
但仍然会出现以下错误
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
答案 0 :(得分:2)
管理以获得以下阻止工作
{
"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')]"
}
}
}
答案 1 :(得分:1)
添加方括号以使JSON类型成为数组而不是字符串
"fileUris": ["[variables('installES')]"]