Azure CLI Installation & usages

How to install Azure CLI in Linux

How to Install AZURE CLI in Linux

Technology keeps evolving and we all know we are in the era of clouds. Many major players in cloud technology like AWS, Azure, and Google with many other names in it.

Azure CLI is just a command-line interface provided by Microsoft Azure.

All are providing GUI based platforms to manage your IT infrastructures like Web Portals or you can say consoles.

These are really friendly for most of the IT infrastructure Professionals but there are thousands of professionals from UNIX Linux background who do not feel accomplished if they use GUI tools.

They love using commands to get things done and having full command over what exactly they are doing and what is expected results.

Many professionals feel accomplished using command-line utilities and they are really needed to automate things. So come Command Line Interface always referred to as CLI. Azure CLI is the same.

What is Azure CLI?

Azure CLI is Microsoft’s cross-platform command-line for managing Azure CLOUD Resources. Azure CLI designed in a way to make it easy to learn and get started with easily.

Azure CLI is a powerful enough great tool for automating the use of Azure Resources. The current version of the Azure CLI is 2.0.81.

Key Features of Azure CLI

Below are the mail features of Azure CLI.

  • It is cross-platform can be installed in Windows and Linux environments.
  • It can be run in Docker and Azure Cloud Shell.
  • It offers command-line flexibility when managing an Azure solution.
  • It supports long-running operations.
  • It has the ability to use one subscription for all commands, or vary subscriptions per command.
  • It has the flexibility to work with multiple clouds.
  • It provides configurable settings.
  • It is deployed with Azure Resource Manager (ARM) deployment templates.

How to install Azure CLI

Based on your environment this procedure might be a little bit different. In our example, if your environment is connected with Azure you can install Azure CLI in your on-prem servers.

Once you install you can start automation related to your Azure Cloud Environment. In the current example, we are looking at the procedure how we can install on Redhat Enterprise Linux.

You need to have python3 running on your Linux server. In the normal Redhat repository, python2.X is getting delivered.

Considering more demand for the growing use of python3 in various projects across many technologies red-hat provides support for the same.

How to install Python3 in RHEL6  

1. Validate what version of python is already running on your Linux server using below.

# rpm -qa |grep -i python*

You can easily found which version of python is already running on your server.

2. You can install Python 3 using the below command. It gets installed with dependencies in
linux server.

# yum --enablerepo=*  install rh-python36.x86_64
====================================================================================
Package                       Arch    Version           Repository    Size
====================================================================================
Installing:
rh-python36                   x86_64  2.0-1.el6          ondemand     3.2 k
Installing for dependencies:
rh-python36-python            x86_64  3.6.3-3.el6        ondemand     54 k
rh-python36-python-devel      x86_64  3.6.3-3.el6        ondemand     918 k
rh-python36-python-libs       x86_64  3.6.3-3.el6        ondemand     7.4 M
rh-python36-python-pip        noarch  9.0.1-2.el6        ondemand     1.8 M
rh-python36-python-setuptools noarch  36.5.0-1.el6       ondemand     585 k
rh-python36-python-virtualenv noarch  15.1.0-2.el6       ondemand     1.8 M
rh-python36-runtime           x86_64  2.0-1.el6          ondemand     1.0 M
scl-utils                     x86_64  20120927-29.el6_9  distro       23 k
scl-utils-build               x86_64  20120927-27.el6_6  ondemand     17 k
Transaction Summary
====================================================================================
Install      10 Package(s)
Total download size: 14 M
Installed size: 54 M
Is this ok [y/N]: y
You can enquire about installed version of python.
# rpm -qa |grep rh-python
rh-python36-python-setuptools-36.5.0-1.el6.noarch
rh-python36-python-3.6.3-3.el6.x86_64
rh-python36-2.0-1.el6.x86_64
rh-python36-python-libs-3.6.3-3.el6.x86_64
rh-python36-python-devel-3.6.3-3.el6.x86_64
rh-python36-runtime-2.0-1.el6.x86_64
rh-python36-python-pip-9.0.1-2.el6.noarch
rh-python36-python-virtualenv-15.1.0-2.el6.noarch

3. Once you install Python3 on linux server you need to configure it by creating links so it works as expected because you already have old version
in server.

# ln -s /opt/rh/rh-python36/root/usr/bin/python /usr/bin/python3.6
# ln -s /opt/rh/rh-python36/root/usr/bin/python /usr/bin/python 

4. We have met pre-requirement. Now for installing Azure CLI we will be working over internet so need to make sure your server is connected to internet a nd there is no firewall blocking traffic.

If so you can run below command to enable traffic though internet on port 8080.Proxy setting you can use your own based on your environment.

# export http_proxy=http://proxy.xxxx.com:8080 
# export https_proxy=http://proxy.xxxxx.com:8080 

That`s it about phthon3 installations which is dependency for Azure CLI . Now lets come back to our main topic how to install azure cli in linux.

How to Install AZURE CLI in Linux

Let us see how to install azure cli in linux.

  • Import Microsoft Keys

You need to import microsoft keys using rpm –import command.

# rpm --import https://packages.microsoft.com/keys/microsoft.asc
Change the system mask for current session
# umask 022 
  • Configure YUM Repository

Setup Azure-cli.repo in /etc/yum.repos.d.

# vi /etc/yum.repos.d/azure-cli.repo        

and add the below contents to the file.

[azure-cli] name=Azure CLI
baseurl=https://packages.microsoft.com/yumrepos/azure-cli enabled=1 gpgcheck=1 
gpgkey=https://packages.microsoft.com/keys/microsoft.asc 
  • Download Azure CLI RPM

  • Now change to directory where you want to download rpm package.For example /tmp.
# cd /tmp 
# yumdownloader azure-cli 

You will have rpm package downloaded in /tmp.Make sure there was no error reported during yumdownloader command.

  • Install Azure CLI RPM

Now you can install rpm with no dependency option.

# rpm -ivh --nodeps azure-cli-*.rpm 

Make sure clean installation of azure-cli package and you are set.

  • Validate Azure CLI Functionality

login to the server as normal id and set proxy as explained above if needed. You can set .profile of your,s to avoid proxy setting every time.

Well all looks good till now.Finally you can check by logging to Azure environment and get ready to execute Azure CLI commands to get things done.This is one time task once server is configured you can use az login command.

  • Azure CLI Commands List

 $ az login

To sign in, use a web browser to open
the page https://microsoft.com/devicelogin
and enter the code A83BG7Y4V to authenticate.
Once you try to login to azure you will
get a message like this. 
You need to open the device URL mentioned 
above and need to enter the code and that,s 
it. 

You can log in to azure with the defined role you can perform tasks as per the level of role you have.

az –version
command-modules-nspkg              2.0.3
core                              2.0.81
nspkg                              3.0.4
telemetry                          1.0.4
Python location ‘/usr/bin/python3’
Extensions directory ‘/home/user/.azure/cliextensions’
Python (Linux) 3.6.3 (default, Jan  9 2018, 10:18:08)
GCC 4.4.7 20120313 (Red Hat 4.4.7-16)]
Legal docs and information: aka.ms/AzureCliLegal
Your CLI is up-to-date.
Please let us know how we are doing: https://aka.ms/clihats

Let us see more about your account details using az account show command.

az account show
{
  “environmentName”: “AzureCloud”,
  “id”: “AZUREID”,
  “isDefault”: true,
  “name”: “SUBSCRIPTION”,
  “state”: “Enabled”,
  “tenantId”: “TENANTID”,
  “user”: {
    “name”: “[email protected]”,
    “type”: “user”
  }
}

Below are a few other common azure cli commands for reference while working with Azure CLI based on groups. It will have variants.

Resource type   Azure CLI command group
Resource Group az group
Virtual Machines az vm
Storage Accounts az storage account
Key Vault az keyvault
Web Applications az webapp
SQL Databases  az sql server
CosmosDB az cosmosdb

 

That`s it as of now all about how to install Azure CLI in linux. . In this article we have seen how to install azure cli in linux  alongside we have seen how to install python3 on rhel6 which is needed as it is required for Azure CLI functionality.You can use same method to to install on RHEL7. 

Conclusion

I hope you will find it really handy. If you like it request you to share as much as you can and do subscribe to our blog to get instant notification for any new post.