Azure Cli - 自动登录(非交互式)

问题描述 投票:0回答:1

“单租户/多订阅”
环境中执行无人值守az login的最佳方式是什么?

在这个例子中。我将使用

--device-code
登录方法。


$ az login --use-device-code

To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code L96AYFHBU to authenticate.

Retrieving tenants and subscriptions for the selection...

[Tenant and subscription selection]

No     Subscription name    Subscription ID     Tenant
-----  -------------------  ------------------  --------------
[1] *  #sub-name-1#         #sub-id-1#          #tenant#
[2]    #sub-name-2#         #sub-id-2#          #tenant#

The default is marked with an *; the default tenant is '#tenant#' and subscription is '#sub-name-1#' (#sub-id-1#).

Select a subscription and tenant (Type a number or Enter for no changes): <enter>

Tenant: #tenant#
Subscription: #sub-name-1# (#sub-id-1#)

[Announcements]
With the new Azure CLI login experience, you can select the subscription you want to use more easily. Learn more about it and its configuration at https://go.microsoft.com/fwlink/?linkid=2271236

If you encounter any problem, please open an issue at https://aka.ms/azclibug

[Warning] The login output has been updated. Please be aware that it no longer displays the full list of available subscriptions by default.

为了避免确认请求,我尝试了

az account set --subscription #sub-name-1#
,但此更改仅订阅默认值,确认提示仍然保留。

我不知道是否有一些

azure config set
可用

无论如何,我找到的唯一解决方法是这个:


az login --use-device-code <<< "\n"


参考资料:

azure azure-active-directory
1个回答
0
投票

为了避免确认请求,我尝试了 az account set --subscription #sub-name-1# 但此更改仅更改订阅默认值,确认提示仍然存在。

您可以运行以下命令来关闭确认提示:

az config set core.disable_confirm_prompt=true

作为替代方案,设置

AZURE_CORE_DISABLE_CONFIRM_PROMPT
环境变量或使用 CLI 配置文件

有关更多详细信息,请参阅CLI 配置值和环境变量

© www.soinside.com 2019 - 2024. All rights reserved.