您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

Azure CLI 配置Azure CLI configuration

Azure CLI 允许用户配置日志记录、数据收集和默认参数值等设置。The Azure CLI allows for user configuration for settings such as logging, data collection, and default argument values. CLI 提供便捷命令 az configure 用于管理某些默认设置。The CLI offers a convenience command for managing some defaults, az configure. 可在配置文件中或使用环境变量设置其他值。Other values can be set in a configuration file or with environment variables.

CLI 使用的配置值按以下优先顺序计算,列表中位于较高位置的项优先。Configuration values used by the CLI are evaluated in the following precedence, with items higher on the list taking priority.

  1. 命令行参数Command-line parameters
  2. 环境变量Environment variables
  3. 配置文件中的值,或使用 az configure 进行设置Values in the configuration file or set with az configure

使用 az configure 进行 CLI 配置CLI configuration with az configure

使用 az configure 命令设置 CLI 的默认值。You set defaults for the CLI with the az configure command. 此命令采用一个参数 --defaults,即 key=value 对的空格分隔列表。This command takes one argument, --defaults, which is a space-separated list of key=value pairs. CLI 使用提供的值来取代所需的参数。The provided values are used by the CLI in place of required arguments.

下表列出了可用的配置键。The following table contains a list of available configuration keys.

NameName 说明Description
groupgroup 所有命令使用的默认资源组。The default resource group to use for all commands.
位置location 所有命令使用的默认位置。The default location to use for all commands.
Webweb az webapp 命令使用的默认应用名称。The default app name to use for az webapp commands.
vmvm az vm 命令使用的默认 VM 名称。The default VM name to use for az vm commands.
vmssvmss 用于 az vmss 命令的默认虚拟机规模集 (VMSS) 名称。The default virtual machine scale set (VMSS) name to use for az vmss commands.
acracr az acr 命令使用的默认容器注册表名称。The default container registry name to use for az acr commands.

例如,可按如下所示设置所有命令的默认资源组和位置。As an example, here's how you would set the default resource group and location for all commands.

az configure --defaults location=westus2 group=MyResourceGroup

CLI 配置文件CLI configuration file

CLI 配置文件包含用于管理 CLI 行为的其他设置。The CLI configuration file contains other settings that are used for managing CLI behavior. 配置文件本身位于 $AZURE_CONFIG_DIR/configThe configuration file itself is located at $AZURE_CONFIG_DIR/config. AZURE_CONFIG_DIR 的默认值为 $HOME/.azure(在 Linux 与 macOS 上)和 %USERPROFILE%\.azure(在 Windows 上)。The default value of AZURE_CONFIG_DIR is $HOME/.azure on Linux and macOS, and %USERPROFILE%\.azure on Windows.

配置文件是以 INI 文件格式编写的。Configuration files are written in the INI file format. 此文件格式定义为节标头后接键-值项的列表。This file format is defined by section headers, followed by a list of key-value entries.

  • 节标头以 [section-name] 的形式写入。Section headers are written as [section-name]. 节名称区分大小写。Section names are case-sensitive.
  • 项以 key=value 的形式写入。Entries are written as key=value. 键名称不区分大小写。Key names are not case-sensitive.
  • 注释是以 #; 开头的任何行。Comments are any line that begins with a # or ;. 不允许内联注释。Inline comments are not allowed.

布尔值不区分大小写,由以下值表示。Booleans are case-insensitive, and are represented by the following values.

  • True:1、yes、true、onTrue: 1, yes, true, on
  • False:0、no、false、offFalse: 0, no, false, off

以下示例 CLI 配置文件禁用任何确认提示,并设置在 /var/log/azure 目录中进行日志记录。Here's an example of a CLI configuration file that disables any confirmation prompts and sets up logging to the /var/log/azure directory.

[core]
disable_confirm_prompt=Yes

[logging]
enable_log_file=yes
log_dir=/var/log/azure

有关所有可用配置值及其含义的详细信息,请参阅下一部分。See the next section for details on all of the available configuration values and what they mean. 有关 INI 文件格式的完整详细信息,请参阅 INI 上的 Python 文档For the full details on the INI file format, see the Python documentation on INI.

CLI 配置值和环境变量CLI configuration values and environment variables

下表包含可在配置文件中放置的所有节和选项名称。The following table contains all of the sections and option names that can be placed in a configuration file. 将其相应环境变量设置为 AZURE_{section}_{name}(全大写)。Their corresponding environment variables are set as AZURE_{section}_{name}, in all caps. 例如,在 AZURE_BATCHAI_STORAGE_ACCOUNT 变量中设置 batchaistorage_account 默认值。For example, the storage_account default for batchai is set in the AZURE_BATCHAI_STORAGE_ACCOUNT variable.

如果提供了默认值,则任何命令都不再需要该参数,When you provide a default value, that argument is no longer required by any command. 而是改用默认值。Instead, the default value is used.

部分Section NameName 类型Type 说明Description
corecore outputoutput 字符串string 默认输出格式。The default output format. 可以是 jsonjsonctsvtableCan be one of json, jsonc, tsv, or table.
disable_confirm_promptdisable_confirm_prompt 布尔值boolean 启用/禁用确认提示。Turn confirmation prompts on/off.
collect_telemetrycollect_telemetry 布尔值boolean 允许 Microsoft 收集有关 CLI 使用情况的匿名数据。Allow Microsoft to collect anonymous data on the usage of the CLI. 有关隐私信息,请参阅 Azure CLI 使用条款For privacy information, see the Azure CLI Terms of Use.
logginglogging enable_log_fileenable_log_file 布尔值boolean 启用/关闭日志记录。Turn logging on/off.
log_dirlog_dir 字符串string 要将日志写入到的目录。The directory to write logs to. 此值默认为 ${AZURE_CONFIG_DIR}/logsBy default this value is ${AZURE_CONFIG_DIR}/logs.
storagestorage connection_stringconnection_string 字符串string az storage 命令使用的默认连接字符串。The default connection string to use for az storage commands.
帐户account 字符串string az storage 命令使用的默认帐户名。The default account name to use for az storage commands.
keykey 字符串string az storage 命令使用的默认帐户密钥。The default account key to use for az storage commands.
sas_tokensas_token 字符串string az storage 命令使用的默认 SAS 令牌。The default SAS token to use for az storage commands.
batchaibatchai storage_accountstorage_account 字符串string az batchai 命令使用的默认存储帐户。The default storage account to use for az batchai commands.
storage_keystorage_key 字符串string az batchai 命令使用的默认存储密钥。The default storage key to use for az batchai commands.
batchbatch 帐户account 字符串string az batch 命令使用的默认 Azure Batch 帐户名。The default Azure Batch account name to use for az batch commands.
access_keyaccess_key 字符串string az batch 命令使用的默认访问密钥。The default access key to use for az batch commands. 只能与 aad 授权配合使用。Only used with aad authorization.
endpointendpoint 字符串string az batch 命令要连接到的默认终结点。The default endpoint to connect to for az batch commands.
auth_modeauth_mode 字符串string az batch 命令使用的授权模式。The authorization mode to use for az batch commands. 可以是 shared_keyaadCan be shared_key or aad.

备注

配置文件中可能包含其他值,但这些值是直接通过 CLI 命令(包括 az configure)管理的。You may see other values in your configuration file, but these are managed directly through CLI commands, including az configure. 你只能自行更改上表中列出的值。The ones listed in the table above are the only values you should change yourself.