[英]Run Azure VM Extension Powershell script from git repository
I am trying to deploy a VM and run an extensions powershell script using ARM Templates.我正在尝试部署 VM 并使用 ARM 模板运行扩展 powershell 脚本。 The script below is responsible to run the extentions for the VM.
下面的脚本负责运行 VM 的扩展。 As can be seen in the part:
从部分可以看出:
"commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -File arm-modules/../../install.ps1 '
The powershell will execute the script file from that location. powershell 将从该位置执行脚本文件。 I want to save the .ps1 file in a git repository and pass the link to the file instead of the local folder.
我想将 .ps1 文件保存在 git 存储库中,并将链接传递给文件而不是本地文件夹。 Something like
"commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -Uri https://raw.githubusercontent.com/.../install.ps1
How can I achieve this?类似于
"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))]"
}
}
}
]
The proper way to do it is to set URL https://raw.githubusercontent.com/.../install.ps1
(URL must be accessible for Azure ARM) to scriptURL
parameter ( "[parameters('scriptURL')]"
in "fileUris"
settings) which is already in your template.正确的做法是将 URL
https://raw.githubusercontent.com/.../install.ps1
ARM 必须可以访问 URL)到scriptURL
参数( "[parameters('scriptURL')]"
在"fileUris"
设置中),它已经在您的模板中。
CustomScriptExtension will download all files fileUris
into your VM to the extension folder, so you can use command as following: CustomScriptExtension 会将所有文件
fileUris
下载到您的 VM 到扩展文件夹中,因此您可以使用以下命令:
"commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -File install.ps1 '
Note:笔记:
You can find CustomScriptExtension logs and downloaded files in VM:您可以在 VM 中找到 CustomScriptExtension 日志和下载的文件:
C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomScriptExtension
C:\Packages\Plugins
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.