![](/img/trans.png)
[英]az vm run-command invoke installing software on azure virtual machine command fails
[英]Azure VM run-command fails with piped commands
我正在嘗試在 Azure 中運行的 ubuntu VM 上安裝 Azure CLI。我正在使用 run-command cli 操作來執行命令az vm run-command invoke --command-id RunShellScript --name trainingVM-1 --resource-group azure-privsec --scripts "curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash"
運行非管道命令時,該命令工作正常但是當我運行上面的管道命令安裝 azure-cli 時,它失敗並出現錯誤: Could not retrieve credential from local cache for service principal 8bf34d22-7230-47e7-907e-e0df201xxxxx. Please run 'az login' for this service principal.
Could not retrieve credential from local cache for service principal 8bf34d22-7230-47e7-907e-e0df201xxxxx. Please run 'az login' for this service principal.
原因之一可能是我使用的是舊版本的 Azure cli(2.29.2)。 目前,我沒有辦法升級 azure-cli 版本。 使用run-command
cli 調用在我的 VM 上安裝azure-cli
的最佳方法是什么。
編輯:拆分成兩個這樣的命令對我有用,但我仍在嘗試查看是否可以將其合並為一個命令:
az vm run-command invoke --command-id RunShellScript --name trainingVM-1 --resource-group azure-privsec --scripts "wget -O /tmp/file.sh https://aka.ms/InstallAzureCLIDeb"
az vm run-command invoke --command-id RunShellScript --name trainingVM-1 --resource-group azure-privsec --scripts "sudo bash /tmp/file.sh"
在 Azure PowerShell 和 Azure DevOps 管道中測試,您的第一個 Azure VM run-command 運行成功。
使用Azure PowerShell ,我可以直接運行這個命令沒有任何問題。
在 DevOps 管道中使用Azure CLI 任務並使用Microsoft 托管的代理。 請確保Azure資源管理器連接(Service Connection)對應的服務主體對你的Azure VM有足夠的權限,比如owner或contributor權限。 然后我可以看到命令成功運行。
有一些文檔供您參考:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.