• 9849-xxx-xxx
  • noreply@example.com
  • Tyagal, Patan, Lalitpur

The Azure CLI

The Azure CLI is a cross-platform CLI management tool for interacting with Azure resources; this can be used instead of the GUI for creating and managing your Azure environments.

Providing cross-platform support means you can install and use it on Windows, Linux, or macOS. It draws parallels to Bash shell scripting and is a popular management tool choice when the focus is on Linux systems and is designed for complex and automation tasks; it is written in Python.

Much like the PowerShell Az module, commands can be executed using interactive commands; they are directly from the shell prompt or using scripts to automate repetitive or complex tasks that have many steps and require actions to be performed against many different entities.

In this case, a series of commands can be assembled in the syntax format of the shell being used, and the script is then executed by issuing a single command at the shell prompt. This is done within the shell of the OS you have installed the Azure CLI on, such as cmd.exe for Windows or Bash for Linux and Mac.

Important Note

Cloud Shell is a Microsoft-provided Shell environment hosted for you on Ubuntu Linux containers (that Microsoft manages and maintains, that you do not pay for); you can think of this as Shell Environment as a Service. The quickest way to start using the Azure CLI is by running it in an Azure Cloud Shell; this can be used instead of a local Shell environment hosted on Windows, Linux, or macOS machines. Using the Azure CLI in Cloud Shell will be covered in the Azure Cloud Shell section of this chapter.

The Azure CLI can be installed for each OS like so:

  • Windows: MSI installer package file format
  • Ubuntu, Debian Linux: apt package manager
  • RHEL, Fedora, CentOS: dnf package manager
  • openSUSE, SLES: zypper package manager
  • macOS: homebrew package manager

You can start using the Azure CLI to perform creation and management tasks as you would do in the portal or via the PowerShell Az module (Azure PowerShell).

To start using the Azure CLI, first, you need to sign in. You can use the following command, which will load an Azure sign-in page; this is referred to as an interactive sign-in:

az login

The syntax (the structure or placement of words or commands, in this case) of the Azure CLI follows a similar but different pattern to PowerShell; it uses the following format pattern:

az <command group> <parameters>

The following are the same example tasks we looked at in the PowerShell section, but this time using the Azure CLI syntax:

  • az login can be used to log in to Azure.
  • az group list will list all resource groups.
  • az group create will create a new resource group.
  • az vm create will create a new VM.

These are just a few Azure CLI examples. We will look at some of these commands in the hands-on exercise in this chapter.

After installing the Azure CLI, you can check its version by running the following command from either the Windows Command Prompt or PowerShell:

az version

The following screenshot shows the command output for Windows PowerShell:

Figure 6.1 – The azure-cli version command from PowerShell

The following screenshot shows the command output for the Windows Command Prompt:

Figure 6.2 – The azure-cli version command from the Windows Command Prompt

This section looked at the Azure CLI as an Azure management tool. The following section will look at Azure Cloud Shell as a browser-based alternative to a Shell environment from a physical or virtual machine.

Leave a Reply

Your email address will not be published. Required fields are marked *