4

Choose the best output format - Azure CLI Tips & Tricks 2

 3 years ago
source link: https://www.thorsten-hans.com/azure-cli-tips-and-tricks-2-choose-the-best-output-format/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Choose the best output format - Azure CLI Tips & Tricks 2

In Azure CLI, you can choose from different output formats. This tip explains how to get results in a particular format and shows how to set your preferred format as default output format for all Azure CLI commands.

Published Tue, May 12, 2020 | by Thorsten Hans | Estimated reading time: 2 min

Azure CLI Tips & Tricks is a collection of small, yet powerful things, that will boost your productivity when working with Microsoft Azure CLI.


Azure CLI provides a bunch of different output formats. By default, it generates output using the json format. Although the default output format is both human-readable and descriptive, it is not the optimal format for every situation. Sometimes you need more focused responses, or you just want a good old ASCII-style table.

As a user, you can choose from the following formats json, jsonc, none, table, tsv, yaml and yamlc.

Use different output formats

You can specify the desired output format for every command using the --output argument, or you use one of the shorter variations like --out and -o.

Azure CLI - Specify the output format explicitly

As an alternative, you can use jsonc or yamlc to get corresponding output with basic colorization, which is helpful when talking about Azure stuff during conference talks, or while explaining things to customers or co-workers.

Azure CLI - Colored YAML output

Another great and typical scenario for overwriting the default output format is when you have a query a unique cloud-resource identifier, which you want to use in constitutive commands. In situations like this, you should consider using the tsv format.

# store the unique Id of an ACR instance for later usage
ACR_ID=$(az acr show -n myacrinstance --query id -o tsv)

echo $ACR_ID
# /subscriptions/111111111111-1111-1111-1111-111111111111/resourceGroups/...

Set the default output format

I use table as my default output format. The default output format can be set by either using the interactivce configuration command az configure, or by editing the Azure CLI configuration file (on unix based systems located at ~/.azure/config) manually, as shown in this quick animation:

Azure CLI - Overwrite the default output format

No matter which format you prefer, make sure to set it as default output format and add the configuration file (~/.azure/config ) to your dotfiles repository.

Tagged: Azure, Azure CLI



About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK