azure - 从 git 存储库运行 Azure VM 扩展 Powershell 脚本
问题描述
我正在尝试使用 ARM 模板部署 VM 并运行扩展 powershell 脚本。下面的脚本负责运行 VM 的扩展。从部分可以看出:
"commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -File arm-modules/../../install.ps1 '
powershell 将从该位置执行脚本文件。我想将 .ps1 文件保存在 git 存储库中,并将链接传递给文件而不是本地文件夹。像"commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -Uri https://raw.githubusercontent.com/.../install.ps1
我怎样才能做到这一点?
"resources": [
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(parameters('virtualMachineName'), '/' ,parameters('virtualMachineName'), 'installGW')]",
"apiVersion": "2019-07-01",
"location": "[parameters('location')]",
"tags": {
"vmname": "[parameters('virtualMachineName')]"
},
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.7",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"[parameters('scriptURL')]"
]
},
"protectedSettings": {
"commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -File arm-modules/.../.../install.ps1 ', if(equals(parameters('existingDataFactoryVersion'), 'V2'), listAuthKeys(parameters('irId'), '2017-09-01-preview').authKey1, listAuthKeys(parameters('irId'), '2015-10-01').key1))]"
}
}
}
]
解决方案
正确的方法是将 URL https://raw.githubusercontent.com/.../install.ps1
(Azure ARM 必须可访问 URL)设置为模板中已有的scriptURL
参数("[parameters('scriptURL')]"
在设置中)。"fileUris"
CustomScriptExtension 会将所有文件下载fileUris
到您的 VM 到扩展文件夹中,因此您可以使用以下命令:
"commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -File install.ps1 '
笔记:
您可以在 VM 中找到 CustomScriptExtension 日志和下载的文件:
C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomScriptExtension
C:\Packages\Plugins
推荐阅读
- python - Python-mysql-connector:停止的 mysql 从站上的 cursor.fetch 失败
- java - 尝试使用 javax 邮件依赖项时出错
- google-maps - 我的流在两次获得纬度和经度后崩溃,并且没有跟随我当前的位置。这是什么原因造成的?
- bash - 使用文件中的数据创建目录名称
- user-interface - 将列转换为行后,在 Kendo UI Grid 加载后更改标题和行标题
- python - 如何在 Google Colab 交互式中制作 matplotlib 图
- javascript - 如何在渲染组件之前更新状态?
- javascript - Jquery:如何将字符串中的 Jquery 变量传递给 alert() 函数?
- java - 扫描 QR 后自动过滤 JTable
- android - 检测何时单击 ScrollView 框架