Vod*_*ase 1 api powershell azure azure-vm-scale-set
目前我正在使用自定义脚本扩展在我的 azure vm 服务器上按需运行脚本作为我们软件解决方案的一部分,我们的另一个开发团队正在将应用程序移动到规模集,我不再能够按需部署自定义脚本扩展到规模集实例。我找到的在规模集实例上运行自定义脚本扩展的唯一解决方案是使用它重新配置部署模板,这种方法对我不利,因为脚本应该按需运行并且经常更改并且每次更新模板是不好的做法。
无论如何,是否可以像在常规虚拟机上一样按需在规模集实例上配置自定义脚本扩展?
在 vm 上进行常规按需脚本部署的 powershell 示例:
Set-AzureRmVMCustomScriptExtension -ResourceGroupName myResourceGroup `
-VMName myVM `
-Location myLocation `
-FileUri myURL `
-Run 'myScript.ps1' `
-Name DemoScriptExtension
Run Code Online (Sandbox Code Playgroud)
小智 5
我找到了一个使用 PowerShell 和 ARM JSON 模板的解决方法(我使用的是 Powershell 版本5.1)。在commandToExecute根据virtualMachineProfile您的JSON模板,指定的值几乎总是发生变化,它会强制执行命令,重新执行运行每模板部署时间。您将在我的模板中看到我添加的:' -Date ', deployment().name到commandToExecute. 的值deployment().name在我的New-AzureRmResourceGroupDeployment命令中指定为:
-Name $($(Get-Date -format "MM_dd_yyyy_HH_mm"))
部署名称基于日期和时间,每分钟会有所不同。
PowerShell 命令:
New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile $PathToJsonTemplate -TemplateParameterFile $PathToParametersFile -Debug -Name $($(Get-Date -format "MM_dd_yyyy_HH_mm")) -force
Run Code Online (Sandbox Code Playgroud)
virtualMachineProfile我的脚本中的自定义脚本扩展部分如下所示(注意commandToExecute):
"virtualMachineProfile": {
"extensionProfile": {
"extensions": [
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "MyExtensionName",
"location": "[parameters('location')]",
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.8",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"[concat(parameters('customScriptExtensionSettings').storageAccountUri, '/scripts/MyScript.ps1')]"
],
"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File MyScript.ps1', ' -Date ', deployment().name)]"
},
"protectedSettings": {
"storageAccountName": "[parameters('customScriptExtensionSettings').storageAccountName]",
"storageAccountKey": "[listKeys(variables('accountid'),'2015-05-01-preview').key1]"
}
}
},
Run Code Online (Sandbox Code Playgroud)
这将允许您在已部署的虚拟机规模集上更新自定义脚本扩展。我希望这有帮助!
| 归档时间: |
|
| 查看次数: |
3242 次 |
| 最近记录: |