2016-09-08 5 views
0

Я следующий фрагмент кода в шаблоне руки для запуска пользовательского сценария на виртуальной машинеAzure 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 

Update 1: I обновлено "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" 

, но все еще такой же ошибкой.

Update 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

ответ

1

Успели получить следующий блок работает

{ 
    "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

Добавить квадратные скобки, чтобы сделать JSON типа массив вместо строки

"fileUris": ["[variables('installES')]"]