Craig Forrester

The Pleasure of Finding Things Out

github linkedin email rss
Azure CLI Basics: Initial Configuration
February 22, 2018
7 minutes read

In my previous post in this series, I discussed how to install Azure CLI using Python’s package manager, pip, and how to use it to keep it updated. In this post, we’ll cover how to set some default configuration.

Verifying Azure CLI Installation

To start with, it’s a good idea to verify the installation works and check the version installed:

PS> az --version
azure-cli (2.0.27)

acr (2.0.21)
acs (2.0.26)
advisor (0.1.2)
appservice (0.1.26)
backup (1.0.6)
batch (3.1.10)
batchai (0.1.5)
billing (0.1.7)
cdn (0.0.13)
cloud (2.0.12)
cognitiveservices (0.1.10)
command-modules-nspkg (2.0.1)
configure (2.0.14)
consumption (0.2.1)
container (0.1.18)
core (2.0.27)
cosmosdb (0.1.19)
dla (0.0.18)
dls (0.0.19)
eventgrid (0.1.10)
extension (0.0.9)
feedback (2.1.0)
find (0.2.8)
interactive (0.3.16)
iot (0.1.17)
keyvault (2.0.18)
lab (0.0.17)
monitor (0.1.2)
network (2.0.23)
nspkg (3.0.1)
profile (2.0.19)
rdbms (0.0.12)
redis (0.2.11)
reservations (0.1.1)
resource (2.0.23)
role (2.0.19)
servicefabric (0.0.10)
sql (2.0.21)
storage (2.0.25)
vm (2.0.26)

Python location 'C:\Python\python.exe'
Extensions directory 'C:\Users\user\.azure\cliextensions'

Python (Windows) 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)]

Legal docs and information: aka.ms/AzureCliLegal

As you can see, this parameter provides a wealth of information, including what versions of Azure CLI is installed, along with the versions of individual modules that it uses. Azure CLI 2.0 is written in Python, so each module is a grouping of Python code that pertains to particular Azure feature/component. So, for example, “vm (2.0.26)” denotes version 2.0.26 of the module for virtual machines. Also, note that the location of Python being used is listed, along with the version — in this case, Python 3.6.4.

Adding Azure CLI to Your PATH

If you see output from the az --version command, then Azure CLI is installed — if you followed along with the previous post, then it should. If you see the following, then you either do not have it installed, or it is not on your PATH:

PS> az --version
az : The term 'az' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ az
+ ~~
   + CategoryInfo          : ObjectNotFound: (az:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException

Your PATH environment variable controls where the operating system looks for commands or scripts to run when your using your shell. If the az command doesn’t work, check your PATH to verify whether or not the Azure CLI installation path is listed:

# Show directories in PATH
$env:PATH -split ';'

If the Azure CLI install path is not listed, try opening a new PowerShell window or Command Prompt. If it still is not listed in your PATH, then you will want to add it to the PATH variable manually. If you installed Azure CLI with the MSI file, on x64 the default path is C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin and you can check whether it exists with PowerShell:

Test-Path -Path 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin'

If you cannot locate the Azure CLI install, you may want to simply reinstall Azure CLI, as it automatically adds the necessary directories to your PATH. You can refer to the previous post for additional information and details on how to install and upgrade Azure CLI with pip on Windows 10.

Viewing Help

To view the help for Azure CLI and list the various commands, type az help:

PS> az help
Group
    az

Subgroups:
    account          : Manage Azure subscription information.
    acr              : Manage Azure Container Registries.
    acs              : Manage Azure Container Services.
    ad               : Manage Azure Active Directory Graph entities needed for Role Based Access
                       Control.
    advisor          : (PREVIEW) Manage Azure Advisor.
    aks              : Manage Azure Kubernetes Services.
    appservice       : Manage App Service plans.
    backup           : Commands to manage Azure Backups.
    batch            : Manage Azure Batch.
    batchai          : Batch AI.
    billing          : Manage Azure Billing.
    cdn              : Manage Azure Content Delivery Networks (CDNs).
    cloud            : Manage registered Azure clouds.
    cognitiveservices: Manage Azure Cognitive Services accounts.
    consumption      : Manage consumption of Azure resources.
    container        : (PREVIEW) Manage Azure Container Instances.
    cosmosdb         : Manage Azure Cosmos DB database accounts.
    disk             : Manage Azure Managed Disks.
    dla              : (PREVIEW) Manage Data Lake Analytics accounts, jobs, and catalogs.
    dls              : (PREVIEW) Manage Data Lake Store accounts and filesystems.
    eventgrid        : Manage Azure Event Grid topics and subscriptions.
    extension        : Manage and update CLI extensions.
    feature          : Manage resource provider features.
    functionapp      : Manage function apps.
    group            : Manage resource groups and template deployments.
    identity         : Managed Service Identities.
    image            : Manage custom virtual machine images.
    iot              : (PREVIEW) Manage Internet of Things (IoT) assets.
    keyvault         : Safeguard and maintain control of keys, secrets, and certificates.
    lab              : Manage Azure DevTest Labs.
    lock             : Manage Azure locks.
    managedapp       : Manage template solutions provided and maintained by Independent Software
                       Vendors (ISVs).
    monitor          : Manage the Azure Monitor Service.
    mysql            : Manage Azure Database for MySQL servers.
    network          : Manage Azure Network resources.
    policy           : Manage resource policies.
    postgres         : Manage Azure Database for PostgreSQL servers.
    provider         : Manage resource providers.
    redis            : Access to a secure, dedicated Redis cache for your Azure applications.
    reservations     : Manage Azure Reservations.
    resource         : Manage Azure resources.
    role             : Manage user roles for access control with Azure Active Directory and service
                       principals.
    sf               : Manage and administer Azure Service Fabric clusters.
    snapshot         : Manage point-in-time copies of managed disks, native blobs, or other
                       snapshots.
    sql              : Manage Azure SQL Databases and Data Warehouses.
    storage          : Manage Azure Cloud Storage resources.
    tag              : Manage resource tags.
    vm               : Provision Linux or Windows virtual machines.
    vmss             : Manage groupings of virtual machines in an Azure Virtual Machine Scale Set
                       (VMSS).
    webapp           : Manage web apps.

Commands:
    configure        : Display and manage the Azure CLI 2.0 configuration. This command is
                       interactive.
    feedback         : Loving or hating the CLI?  Let us know!
    find             : Find Azure CLI commands.
    interactive      : Start interactive mode.
    login            : Log in to Azure.
    logout           : Log out to remove access to Azure subscriptions.

As you can see, there are a lot commands spanning many Azure features.

Initial Configuration

When you first use Azure CLI, it’s a good idea to configure some defaults to make the experience for interacive use easier. Use az configure to kick off the interactive configuration routine.

Here is what it looks like:

PS> az configure

Welcome to the Azure CLI! This command will guide you through logging in and setting some default values.

Your settings can be found at C:\Users\Craig Forrester\.azure\config
Your current configuration is as follows:

[cloud]
name = AzureCloud

Do you wish to change your settings? (y/N): y

What default output format would you like?
 [1] json - JSON formatted output that most closely matches API responses
 [2] jsonc - Colored JSON formatted output that most closely matches API responses
 [3] table - Human-readable output format
 [4] tsv - Tab- and Newline-delimited, great for GREP, AWK, etc.
Please enter a choice [1]: 3

Would you like to enable logging to file? (y/N): n

Microsoft would like to collect anonymous Azure CLI usage data to improve our CLI.  Participation is voluntary and when you choose to participate, your device automatically sends information to Microsoft about how you use Azure CLI.  To update your choice, run "az configure" again.
Select y to enable data collection. (Y/n): n

You're all set! Here are some commands to try:
 $ az login
 $ az vm create --help
 $ az feedback

For interactive use, I like to set the default output format to table, which will place output in columns. You can change this whenever you wish, per command line, with the --output parameter, so don’t worry about losing functionality.

Azure CLI Configuration File

The configuration for Azure CLI is located in one of a couple of locations by default. From the documentation:

“The configuration file itself is located at $AZURE_CONFIG_DIR/config. The default value of AZURE_CONFIG_DIR is $HOME/.azure/config on Linux and macOS, and %USERPROFILE%\.azure\config on Windows.”

To view the Azure CLI configuration path in PowerShell on Windows, use $env:USERPROFILE\.azure\config:

PS> cat $env:USERPROFILE\.azure\config
[cloud]
name = AzureCloud

[core]
first_run = yes
output = table
collect_telemetry = no

[logging]
enable_log_file = yes

[defaults]
group =

These are just a few of the options available, which the initial configuration routine sets.

Default Logging Directory

If you enable logging, you will want to know where it is. The default log file location is ${AZURE_CONFIG_DIR}/logs; on Windows you can view this in your user profile, in the .azure directory:

PS> Test-Path $env:USERPROFILE\.azure\logs\az.log
True

For complete details on this and other configuration options, take a look at the documentation for Azure CLI configuration options.

In the next post, I’ll talk about how to log in, log out, and switch between subscriptions with Azure CLI.


Back to posts