From 96c3cb1d5723572feb08405843f56fb51bd4a006 Mon Sep 17 00:00:00 2001 From: Jun Shi Date: Wed, 28 Aug 2019 17:12:37 +0800 Subject: [PATCH] [DocsArchive-1.0.0.0](2019-08-28-17-12-09)Auto archive content --- .openpublishing.redirection.json | 59 ++ docs-ref-conceptual/TOC.yml | 44 -- docs-ref-conceptual/authenticate-azure-cli.md | 61 --- .../azure-cli-configuration.md | 107 ---- docs-ref-conceptual/azure-cli-extensions.md | 94 ---- ...te-an-azure-service-principal-azure-cli.md | 239 --------- .../format-output-azure-cli.md | 140 ----- .../get-started-with-azure-cli.md | 442 --------------- docs-ref-conceptual/install-azure-cli.md | 507 ------------------ docs-ref-conceptual/interactive-azure-cli.md | 121 ----- .../manage-azure-subscriptions-azure-cli.md | 60 --- docs-ref-conceptual/overview.md | 47 -- docs-ref-conceptual/query-azure-cli.md | 165 ------ 13 files changed, 59 insertions(+), 2027 deletions(-) create mode 100644 .openpublishing.redirection.json delete mode 100644 docs-ref-conceptual/authenticate-azure-cli.md delete mode 100644 docs-ref-conceptual/azure-cli-configuration.md delete mode 100644 docs-ref-conceptual/azure-cli-extensions.md delete mode 100644 docs-ref-conceptual/create-an-azure-service-principal-azure-cli.md delete mode 100644 docs-ref-conceptual/format-output-azure-cli.md delete mode 100644 docs-ref-conceptual/get-started-with-azure-cli.md delete mode 100644 docs-ref-conceptual/install-azure-cli.md delete mode 100644 docs-ref-conceptual/interactive-azure-cli.md delete mode 100644 docs-ref-conceptual/manage-azure-subscriptions-azure-cli.md delete mode 100644 docs-ref-conceptual/overview.md delete mode 100644 docs-ref-conceptual/query-azure-cli.md diff --git a/.openpublishing.redirection.json b/.openpublishing.redirection.json new file mode 100644 index 000000000..7e1cd76a1 --- /dev/null +++ b/.openpublishing.redirection.json @@ -0,0 +1,59 @@ +{ + "redirections": [ + { + "source_path": "docs-ref-conceptual/overview.md", + "redirect_url": "/juns_archive_test/azure-cli-docs-dev-juns-archive/overview", + "redirect_document_id": true + }, + { + "source_path": "docs-ref-conceptual/install-azure-cli.md", + "redirect_url": "/juns_archive_test/azure-cli-docs-dev-juns-archive/install-azure-cli", + "redirect_document_id": true + }, + { + "source_path": "docs-ref-conceptual/get-started-with-azure-cli.md", + "redirect_url": "/juns_archive_test/azure-cli-docs-dev-juns-archive/get-started-with-azure-cli", + "redirect_document_id": true + }, + { + "source_path": "docs-ref-conceptual/authenticate-azure-cli.md", + "redirect_url": "/juns_archive_test/azure-cli-docs-dev-juns-archive/authenticate-azure-cli", + "redirect_document_id": true + }, + { + "source_path": "docs-ref-conceptual/create-an-azure-service-principal-azure-cli.md", + "redirect_url": "/juns_archive_test/azure-cli-docs-dev-juns-archive/create-an-azure-service-principal-azure-cli", + "redirect_document_id": true + }, + { + "source_path": "docs-ref-conceptual/interactive-azure-cli.md", + "redirect_url": "/juns_archive_test/azure-cli-docs-dev-juns-archive/interactive-azure-cli", + "redirect_document_id": true + }, + { + "source_path": "docs-ref-conceptual/manage-azure-subscriptions-azure-cli.md", + "redirect_url": "/juns_archive_test/azure-cli-docs-dev-juns-archive/manage-azure-subscriptions-azure-cli", + "redirect_document_id": true + }, + { + "source_path": "docs-ref-conceptual/format-output-azure-cli.md", + "redirect_url": "/juns_archive_test/azure-cli-docs-dev-juns-archive/format-output-azure-cli", + "redirect_document_id": true + }, + { + "source_path": "docs-ref-conceptual/query-azure-cli.md", + "redirect_url": "/juns_archive_test/azure-cli-docs-dev-juns-archive/query-azure-cli", + "redirect_document_id": true + }, + { + "source_path": "docs-ref-conceptual/azure-cli-extensions.md", + "redirect_url": "/juns_archive_test/azure-cli-docs-dev-juns-archive/azure-cli-extensions", + "redirect_document_id": true + }, + { + "source_path": "docs-ref-conceptual/azure-cli-Configuration.md", + "redirect_url": "/juns_archive_test/azure-cli-docs-dev-juns-archive/azure-cli-configuration", + "redirect_document_id": true + } + ] +} \ No newline at end of file diff --git a/docs-ref-conceptual/TOC.yml b/docs-ref-conceptual/TOC.yml index db5c7cb93..c063536f5 100644 --- a/docs-ref-conceptual/TOC.yml +++ b/docs-ref-conceptual/TOC.yml @@ -1,47 +1,3 @@ -- name: Azure CLI 2.0 - href: overview.md - items: - - name: Install - href: install-azure-cli.md - - name: Get started - href: get-started-with-azure-cli.md - - name: Cloud shell - href: /azure/cloud-shell/overview - - name: Log in - href: authenticate-azure-cli.md - items: - - name: Create a service principal - href: create-an-azure-service-principal-azure-cli.md - - name: Using Managed Service Identities - items: - - name: Configure MSI for an Azure VM - href: /azure/active-directory/msi-qs-configure-cli-windows-vm?toc=%2fcli%2fazure%2ftoc.json&bc=%2fcli%2fazure%2fbreadcrumb%2ftoc.json - - name: Sign in on an Azure VM using MSI - href: /azure/active-directory/msi-how-to-get-access-token-using-msi?toc=%2fcli%2fazure%2ftoc.json&bc=%2fcli%2fazure%2fbreadcrumb%2ftoc.json - - name: Interactive mode - href: interactive-azure-cli.md - - name: Deployment templates - items: - - name: Use deployment templates - href: /azure/azure-resource-manager/resource-group-template-deploy-cli?toc=%2fcli%2fazure%2ftoc.json&bc=%2fcli%2fazure%2fbreadcrumb%2ftoc.json - - name: Export deployment templates - href: /azure/azure-resource-manager/resource-manager-export-template-cli?toc=%2fcli%2fazure%2ftoc.json&bc=%2fcli%2fazure%2fbreadcrumb%2ftoc.json - - name: Deploy from private templates - href: /azure/azure-resource-manager/resource-manager-cli-sas-token?toc=%2fcli%2fazure%2ftoc.json&bc=%2fcli%2fazure%2fbreadcrumb%2ftoc.json - - name: Manage subscriptions - href: manage-azure-subscriptions-azure-cli.md - - name: Work with multiple clouds - href: manage-clouds-azure-cli.md?toc=%2fcli%2fazure%2ftoc.json&bc=%2fcli%2fazure%2fbreadcrumb%2ftoc.json - - name: Output formats - href: format-output-azure-cli.md - - name: Query - href: query-azure-cli.md - - name: Extensions - href: azure-cli-extensions.md - - name: Configuration settings - href: azure-cli-Configuration.md - - name: Release notes - href: release-notes-azure-cli.md?toc=%2fcli%2fazure%2ftoc.json&bc=%2fcli%2fazure%2fbreadcrumb%2ftoc.json - name: Sample Scripts items: - name: Linux VMs diff --git a/docs-ref-conceptual/authenticate-azure-cli.md b/docs-ref-conceptual/authenticate-azure-cli.md deleted file mode 100644 index 74070da27..000000000 --- a/docs-ref-conceptual/authenticate-azure-cli.md +++ /dev/null @@ -1,61 +0,0 @@ ---- -title: Log in with Azure CLI 2.0 -description: Log in with Azure 2.0 CLI on Linux, Mac, or Windows. -keywords: Azure CLI 2.0, login, Azure CLI, authentication, authorize, log in -author: sptramer -ms.author: stttramer -manager: routlaw -ms.date: 11/13/2017 -ms.topic: article -ms.prod: azure -ms.technology: azure -ms.devlang: azurecli -ms.service: multiple -ms.assetid: 65becd3a-9d69-4415-8a30-777d13a0e7aa ---- - -# Log in with Azure CLI 2.0 - -There are several ways to log in and authenticate with the Azure CLI. The simplest way to get started is to log in interactively through your browser, or to log in at the command line. Our recommended approach is to use service principals, which provide a way for you to create non-interactive accounts that you can use to manipulate resources. By granting just the appropriate permissions needed to a service principal, you can ensure your automation scripts are even more secure. - -None of your private credential information is stored locally. Instead, an authentication token is generated by Azure and stored. After logging in, your local login token is valid until it goes for 14 days without being used. At that point, you will need to re-authenticate. - -After logging in, CLI Commands are run against your default subscription. If you have more than one subscription, you may want to [change your default subscription](manage-azure-subscriptions-azure-cli.md). - -## Interactive log-in - -Log in interactively from your web browser. - -[!INCLUDE [interactive_login](includes/interactive-login.md)] - -## Command line - -Provide your credentials on the command line. - -> [!Note] -> This approach doesn't work with Microsoft accounts or accounts that have two-factor authentication enabled. - -```azurecli-interactive -az login -u -p -``` - -## Logging in with a service principal - -Service principals are like user accounts to which you can apply rules using Azure Active Directory. -Authenticating with a service principal is the best way to secure the usage of your Azure resources -from either your scripts or applications that manipulate resources. If you don't already have a service principal available and -would like to create one, see [Create an Azure service principal with the Azure CLI](create-an-azure-service-principal-azure-cli.md). - -To log in with a service principal, you provide the username, password or certificate PEM file, and the tenant associated with the service principal: - -```azurecli-interactive -az login --service-principal -u -p --tenant -``` - -The tenant value is the Azure Active Directory tenant associated with the service principal. This can either be an .onmicrosoft.com domain, or the Azure object ID for the tenant. -You can get the tenant object ID for your current login by using the following command: - -```azurecli -az account show --query 'tenantId' -o tsv -``` - diff --git a/docs-ref-conceptual/azure-cli-configuration.md b/docs-ref-conceptual/azure-cli-configuration.md deleted file mode 100644 index 570435b53..000000000 --- a/docs-ref-conceptual/azure-cli-configuration.md +++ /dev/null @@ -1,107 +0,0 @@ ---- -title: Azure CLI configuration options -description: How to configure the Azure CLI 2.0 -keywords: Azure CLI, configuration, settings, Azure -author: sptramer -ms.author: sttramer -manager: routlaw -ms.date: 12/13/2017 -ms.topic: article -ms.prod: azure -ms.technology: azure -ms.devlang: azurecli -ms.service: multiple ---- - -# Azure CLI 2.0 configuration - -The Azure CLI 2.0 allows for user configuration to override internal settings such as logging and data collection, and provide default options for -some required parameters. The CLI offers a convenience command for managing some of these values, `az configure`, and other values can be set in a -configuration file or with environment variables. - -Configuration values used by the CLI are evaluted in the following precedence, with items higher on the list taking priority. - -1. Command-line parameters -2. Environment variables -3. Values in the configuration file or set with `az configure` - -## CLI configuration with az configure - -You set defaults for the CLI with the [az configure](/cli/azure/?view=azure-cli-latest#az_configure) command. -This command takes one argument, `--defaults`, which is a space-separated list of `key=value` pairs. The provded values are used by the CLI in place of -required arguments. - -The following is a list of available keys that you can use. - -| Name | Description | -|------|-------------| -| group | The default resource group to use for all commands. | -| location | The default location to use for all commands. | -| web | The default app name to use for `az webapp` commands. | -| vm | The default VM name to use for `az vm` commands. | -| vmss | The default VMSS name to use for `az vmss` commands. | -| acr | The default container registry name to use for `az acr` commands. | -| acs | The default container service name to use for `az acs` commands. | - -As an example, here's how you would set the default resource group and location for all commands. - -```azurecli -az configure --defaults "location=westus2 group=MyResourceGroup" -``` - -## CLI configuration file - -The CLI configuration file contains other settings that are used for managing CLI behavior. 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. - -Configuration files are written in the INI file format. These files are made up of sections which start with a `[section-name]` header, followed by -a list of `key=value` entries. Section names are case-sensitive and key names are not. -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, on -* __False__: 0, no, false, off - -Here's an example of a CLI configuration file which 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. For the full details on the INI file format, -see the [Python documentation on INI](https://docs.python.org/3/library/configparser.html#supported-ini-file-structure). - -## 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. Their corresponding -environment variables can be set as `AZURE_{section}_{name}`, in all caps. For example, you can set the `batchai` section's `storage_account` default -in the `AZURE_BATCHAI_STORAGE_ACCOUNT` variable. - -Any value with a default available does not have to be present in the command line arguments, even if it is required. - -| Section | Name | Type | Description| -|---------|-----------|------|------------| -| __core__ | output | string | The default output format. Can be one of `json`, `jsonc`, `tsv`, or `table`. | -| | disable\_confirm\_prompt | boolean | Turn confirmation prompts on/off. | -| | collect\_telemetry | boolean | Allow Microsoft to collect anonymous data on the usage of the CLI. For privacy information, see the [Azure CLI 2.0 Terms of Use](http://aka.ms/AzureCliLegal). | -| __logging__ | enable\_log\_file | boolean | Turn logging on/off. | -| | log\_dir | string | The directory to write logs to. By default this is `${AZURE_CONFIG_DIR}/logs`. | -| __storage__ | connection\_string | string | The default connection string to use for `az storage` commands. | -| | account | string | The default account name to use for `az storage` commands. | -| | key | string | The default account key to use for `az storage` commands. | -| | sas\_token | string | The default SAS token to use for `az storage` commands. | -| __batchai__ | storage\_account | string | The default storage account to use for `az batchai` commands. | -| | storage\_key | string | The default storage key to use for `az batchai` commands. | -| __batch__ | account | string | The default Azure Batch account name to use for `az batch` commands. | -| | access\_key | string | The default access key to use for `az batch` commands. Only used with `aad` authorization. | -| | endpoint | string | The default endpoint to connect to for `az batch` commands. | -| | auth\_mode | string | The authorization mode to use for `az batch` commands. Can be `shared_key` or `aad`. | - -> [!NOTE] -> 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. diff --git a/docs-ref-conceptual/azure-cli-extensions.md b/docs-ref-conceptual/azure-cli-extensions.md deleted file mode 100644 index 9eaa90baa..000000000 --- a/docs-ref-conceptual/azure-cli-extensions.md +++ /dev/null @@ -1,94 +0,0 @@ ---- -title: Azure CLI 2.0 Extensions -description: Using extensions with the Azure CLI 2.0 -keywords: Azure CLI, Extensions -author: sptramer -ms.author: sttramer -manager: routlaw -ms.date: 10/30/2017 -ms.topic: article -ms.prod: azure -ms.technology: azure -ms.devlang: azurecli -ms.service: multiple ---- - -# Using extensions with the Azure CLI 2.0 - -Extensions are individual modules not shipped with the Azure CLI itself that allow you to add functionality through new commands. These might be experimental or pre-release offerings, specialized tools that Microsoft has for your needs, or even extensions that you yourself have written. Extensions allow for a degree of flexibility with the CLI that let you modify it to your own needs, without having to ship a lot of additional packages that aren't considered part of the core feature set. - -This article will help you understand how to install, update, and remove extensions for the CLI. It should also answer common questions about extension behavior. - -## Finding extensions - -In order to know what extensions are available, you can use `az extension list-available`. This command lists the available, official extensions which are provided and supported by Microsoft. - -## Installing extensions - -Once you have found an extension to install, use `az extension add` to get it. If the extension is an official Microsoft extension listed in `az extension list-available`, you can install the extension -by name. - -```azurecli -az extension add --name -``` - -If the extension is from an external resource or you have a direct link to it, you can provide the source URL or local path. This _must_ be a compiled Python wheel file. - -```azurecli -az extension add --source -``` - -Once an extension is installed, it can be found under the value of the `$AZURE_EXTENSION_DIR` shell variable. If this variable is unset, by default the value is `$HOME/.azure/cliextensions` on Linux and macOS, and `%USERPROFILE%\.azure\cliextensions` on Windows. - -## Updating extensions - -Extensions can only be updated by name: - -```azurecli -az extension update --name -``` - -If an extension name cannot be resolved by the CLI for whatever reason, reinstall the extension to -update it. There is also the possibility that the extension was moved out of preview and became a -built-in command for the CLI. In that case, update the CLI and uninstall the extension. - -## Uninstalling extensions - -If you no longer need an extension, it can be removed with `az extension remove`, - -```azurecli -az extension remove --name -``` - -You can also remove an extension manually by deleting it from the location where it was installed. This will be the value of the `$AZURE_EXTENSION_DIR` shell variable. If this variable is unset, by default the value is `$HOME/.azure/cliextensions` on Linux and macOS, and `%USERPROFILE%\.azure\cliextensions` on Windows. - -```bash -rm -rf $AZURE_EXTENSION_DIR/ -``` - -It is recommended that you uninstall using `az extension remove`. - -## FAQ - -Here are some answers to other common questions about CLI extensions. - -### What file formats are allowed for installation? - -Currently, only compiled Python wheels can be installed as extensions. - -### Can extensions replace existing commands? - -Yes. Extensions may replace existing commands, but before running a command that has been replaced the CLI will issue a warning. - -### How can I tell if an extension is in pre-release? - -An extension should indicate through its own documentation and versioning if it is in pre-release. It is also common for Microsoft to release preview commands for the CLI as extensions, -with plans to move them into the main CLI interface once the product is out of preview. - -### Can extensions depend upon each other? - -No. Extensions must be individual packages which do not rely on one another. This is because the CLI gives no guarantee about when extensions are loaded, so dependencies could not be guaranteed to be satisfied. Installing an extension installs that extension only, and it should continue to work even if you remove other extensions. - -### Are extensions updated along with the CLI? - -No. Extensions must be updated separately, as described in the [Updating extensions](#updating-extensions) section. diff --git a/docs-ref-conceptual/create-an-azure-service-principal-azure-cli.md b/docs-ref-conceptual/create-an-azure-service-principal-azure-cli.md deleted file mode 100644 index e6cce20a6..000000000 --- a/docs-ref-conceptual/create-an-azure-service-principal-azure-cli.md +++ /dev/null @@ -1,239 +0,0 @@ ---- -title: Create an Azure service principal with Azure CLI 2.0 -description: Learn how to create a service principal for your app or service with Azure CLI 2.0. -keywords: Azure CLI 2.0, Azure Active Directory, Azure Active directory, AD, RBAC -author: rloutlaw -ms.author: routlaw -manager: douge -ms.date: 10/12/2017 -ms.topic: article -ms.prod: azure -ms.technology: azure -ms.devlang: azurecli -ms.service: multiple -ms.assetid: fab89cb8-dac1-4e21-9d34-5eadd5213c05 ---- - -# Create an Azure service principal with Azure CLI 2.0 - -If you plan to manage your app or service with Azure CLI 2.0, -you should run it under an Azure Active Directory (AAD) service principal rather than your own credentials. -This topic steps you through creating a security principal with Azure CLI 2.0. - -> [!NOTE] -> You can also create a service principal through the Azure portal. -> Read [Use portal to create Active Directory application and service principal that can access resources](/azure/azure-resource-manager/resource-group-create-service-principal-portal) for more details. - -## What is a 'service principal'? - -An Azure service principal is a security identity used by user-created apps, services, and automation tools to access specific Azure resources. Think of it as a 'user identity' (login and password or certificate) with a specific role, and tightly controlled permissions to access your resources. It only needs to be able to do specific things, unlike a general user identity. It improves security if you only grant it the minimum permissions level needed to perform its management tasks. - -Azure CLI 2.0 supports the creation of password-based authentication credentials and certificate credentials. In this topic, we cover both types of credentials. - -## Verify your own permission level - -First, you must have sufficient permissions in both your Azure Active Directory and your Azure subscription. Specifically, you must be able to create an app in the Active Directory, and assign a role to the service principal. - -The easiest way to check whether your account has adequate permissions is through the portal. See [Check required permission in portal](/azure/azure-resource-manager/resource-group-create-service-principal-portal#required-permissions). - -## Create a service principal for your application - -You must have one of the following to identify the app you want to create a service principal for: - - * The unique name or URI of your deployed app (such as "MyDemoWebApp" in the examples), or - * the Application ID, the unique GUID associated with your deployed app, service, or object - -These values identify your application when creating a service principal. - -### Get information about your application - -Get identity information about your application with the `az ad app list`. - -[!INCLUDE [cloud-shell-try-it.md](includes/cloud-shell-try-it.md)] - -```azurecli-interactive -az ad app list --display-name MyDemoWebApp -``` - -```json -{ - "appId": "a487e0c1-82af-47d9-9a0b-af184eb87646d", - "appPermissions": null, - "availableToOtherTenants": false, - "displayName": "MyDemoWebApp", - "homepage": "http://MyDemoWebApp.azurewebsites.net", - "identifierUris": [ - "http://MyDemoWebApp" - ], - "objectId": "bd07205b-629f-4a2e-945e-1ee5dadf610b9", - "objectType": "Application", - "replyUrls": [] - } -``` - -The `--display-name` option filters the returned list of apps to show those with `displayName` starting with MyDemoWebApp. - -### Create a service principal with a password - -Use [az ad sp create-for-rbac](/cli/azure/ad/sp#create-for-rbac) and the `--password` parameter to create the service principal with a password. When you do not provide a role or scope, it defaults to the **Contributor** role for the current subscription. If you create a service principal without using either the `--password` or `--cert` parameter, password authentication is used and a password is generated for you. - -```azurecli-interactive -az ad sp create-for-rbac --name {appName} --password "{strong password}" -``` - -```json -{ - "appId": "a487e0c1-82af-47d9-9a0b-af184eb87646d", - "displayName": "MyDemoWebApp", - "name": "http://MyDemoWebApp", - "password": {strong password}, - "tenant": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" -} -``` - - > [!WARNING] - > Don't create an insecure password. Follow the - > [Azure AD password rules and restrictions](/azure/active-directory/active-directory-passwords-policy) guidance. - -### Create a service principal with a self-signed certificate - -Use [az ad sp create-for-rbac](/cli/azure/ad/sp#create-for-rbac) and the `--create-cert` parameter to create a self-signed certificate. - -```azurecli-interactive -az ad sp create-for-rbac --name {appName} --create-cert -``` - -```json -{ - "appId": "c495db57-82e0-4e2e-9369-069dff176858", - "displayName": "azure-cli-2017-10-12-22-15-38", - "fileWithCertAndPrivateKey": "/.pem", - "name": "http://MyDemoWebApp", - "password": null, - "tenant": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" -} -``` - -Copy the value of the `fileWithCertAndPrivateKey` response. This is the certificate file which will be used for authentication. - -For more options when using certificates, see [az ad sp create-for-rbac](/cli/azure/ad/sp#create-for-rbac). - -### Get information about the service principal - -```azurecli-interactive -az ad sp show --id {appID} -``` - -```json -{ - "appId": "a487e0c1-82af-47d9-9a0b-af184eb87646d", - "displayName": "MyDemoWebApp", - "objectId": "0ceae62e-1a1a-446f-aa56-2300d176659bde", - "objectType": "ServicePrincipal", - "servicePrincipalNames": [ - "http://MyDemoWebApp", - "a487e0c1-82af-47d9-9a0b-af184eb87646d" - ] -} -``` - -### Sign in using the service principal - -You can now log in as the new service principal for your app using the *appId* from `az ad sp show`, and either the *password* or the path to the created certificate. Supply the *tenant* value from the results of `az ad sp create-for-rbac`. - -```azurecli-interactive -az login --service-principal -u {appID} --password {password-or-path-to-cert} --tenant {tenant} -``` - -You will see this output after a successful sign-on: - -```json -[ - { - "cloudName": "AzureCloud", - "id": "a487e0c1-82af-47d9-9a0b-af184eb87646d", - "isDefault": true, - "state": "Enabled", - "tenantId": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", - "user": { - "name": "https://MyDemoWebApp", - "type": "servicePrincipal" - } - } -] -``` - -Use the `id`, `password`, and `tenant` values as the credentials for running your app. - -## Managing roles - -> [!NOTE] -> Azure Role-Based Access Control (RBAC) is a model for defining and managing roles for user and service principals. -> Roles have sets of permissions associated with them, -> which determine the resources a principal can read, access, write, or manage. -> For more information on RBAC and roles, see [RBAC: Built-in roles](/azure/active-directory/role-based-access-built-in-roles). - -The Azure CLI 2.0 provides the following commands to manage role assignments: - -* [az role assignment list](/cli/azure/role/assignment#list) -* [az role assignment create](/cli/azure/role/assignment#create) -* [az role assignment delete](/cli/azure/role/assignment#delete) - -The default role for a service principal is **Contributor**. It may not be the best choice for an app's interactions with Azure services, given its broad permissions. The **Reader** role is more restrictive and is a good choice for read-only access. You can view details on role-specific permissions or create custom ones through the Azure portal. - -In this example, add the **Reader** role to our prior example, and delete the **Contributor** -one: - -```azurecli-interactive -az role assignment create --assignee a487e0c1-82af-47d9-9a0b-af184eb87646d --role Reader -az role assignment delete --assignee a487e0c1-82af-47d9-9a0b-af184eb87646d --role Contributor -``` - -Verify the changes by listing the currently assigned roles: - -```azurecli-interactive -az role assignment list --assignee a487e0c1-82af-47d9-9a0b-af184eb87646d -``` - -```json -{ - "id": "/subscriptions/34345f33-0398-4a99-a42b-f6613d1664ac/providers/Microsoft.Authorization/roleAssignments/c27f78a7-9d3b-404b-ab59-47818f9af9ac", - "name": "c27f78a7-9d3b-404b-ab59-47818f9af9ac", - "properties": { - "principalId": "790525226-46f9-4051-b439-7079e41dfa31", - "principalName": "http://MyDemoWebApp", - "roleDefinitionId": "/subscriptions/34345f33-0398-4a99-a42b-f6613d1664ac/providers/Microsoft.Authorization/roleDefinitions/acdd72a7-3385-48ef-bd42-f606fba81ae7", - "roleDefinitionName": "Reader", - "scope": "/subscriptions/34345f33-0398-4a99-a42b-f6613d1664ac" - }, - "type": "Microsoft.Authorization/roleAssignments" -} -``` - -> [!NOTE] -> If your account does not have sufficient permissions to assign a role, you see an error message. -> The message states your account "does not have authorization to perform action -> 'Microsoft.Authorization/roleAssignments/write' over scope '/subscriptions/{guid}'." - -## Change the credentials of a security principal - -It's a good security practice to review permissions and update passwords regularly. You may also want to manage and modify the security credentials as your app changes. - -### Reset a service principal password - -Use `az ad sp reset-credentials` to reset the current password for the service principal. - -```azurecli-interactive -az ad sp reset-credentials --name 20bce7de-3cd7-49f4-ab64-bb5b443838c3 --password {new-password} -``` - -```json -{ - "appId": "a487e0c1-82af-47d9-9a0b-af184eb87646d", - "name": "a487e0c1-82af-47d9-9a0b-af184eb87646d", - "password": {new-password}, - "tenant": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" -} -``` - -The CLI generates a secure password if you leave out the `--password` option. diff --git a/docs-ref-conceptual/format-output-azure-cli.md b/docs-ref-conceptual/format-output-azure-cli.md deleted file mode 100644 index bf7a26d30..000000000 --- a/docs-ref-conceptual/format-output-azure-cli.md +++ /dev/null @@ -1,140 +0,0 @@ ---- -title: Output formats for Azure CLI 2.0 -description: Use --output to format the output of Azure CLI 2.0 commands to tables, lists or json. -keywords: Azure CLI 2.0, output, format, table, list, json, Linux, Mac, Windows, OS X -author: rloutlaw -ms.author: routlaw -manager: douge -ms.date: 02/27/2017 -ms.topic: article -ms.prod: azure -ms.technology: azure -ms.devlang: azurecli -ms.service: multiple -ms.assetid: 74bdb727-481d-45f7-a44e-15d18dc55483 ---- - -# Output formats for Azure CLI 2.0 commands - -Azure CLI 2.0 uses json as its default output option, but offers various ways for you to format the output of any command. Use the `--output` (or `--out` or `-o`) parameter to format the output of the command into one of the output types noted in the following table. - ---output | Description ----------|------------------------------- -`json` | json string. `json` is the default. -`jsonc` | colorized json string. -`table` | table with column headings. -`tsv` | tab-separated values. - -[!INCLUDE [cloud-shell-try-it.md](includes/cloud-shell-try-it.md)] - -## Using the json option - -The following example displays the list of virtual machines in your subscriptions in the default json format. - -```azurecli-interactive -az vm list --output json -``` - -The results are in this form (only showing partial output for sake of brevity). - -```json -[ - { - "availabilitySet": null, - "diagnosticsProfile": null, - "hardwareProfile": { - "vmSize": "Standard_DS1" - }, - "id": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/DEMORG1/providers/Microsoft.Compute/virtualMachines/DemoVM010", - "instanceView": null, - "licenseType": null, - "location": "westus", - "name": "DemoVM010", - "networkProfile": { - "networkInterfaces": [ - { - "id": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/demorg1/providers/Microsoft.Network/networkInterfaces/DemoVM010VMNic", - "primary": null, - "resourceGroup": "demorg1" - } - ] - }, - ... - ... - ... -] -``` - -## Using the table option - -The table option provides an easy to read set of output, but note that nested objects are not included in the output with the simple `--output table`, unlike the preceding .json example. Using the same example with 'table' output format provides a curated list of most common property values. - -```azurecli-interactive -az vm list --out table -``` - -``` -Name ResourceGroup Location ------------ --------------- ---------- -DemoVM010 DEMORG1 westus -demovm212 DEMORG1 westus -demovm213 DEMORG1 westus -KBDemo001VM RGDEMO001 westus -KBDemo020 RGDEMO001 westus -``` - -You can use the `--query` parameter to customize the properties and columns you want to show in the list output. The following example shows how to select just the VM Name and the Resource Group Name in the `list` command. - -```azurecli-interactive -az vm list --query "[].{ resource: resourceGroup, name: name }" -o table -``` - -``` -Resource Name ----------- ----------- -DEMORG1 DemoVM010 -DEMORG1 demovm212 -DEMORG1 demovm213 -RGDEMO001 KBDemo001VM -RGDEMO001 KBDemo020 -``` - -## Using the tsv option - -'tsv' output format returns a simple text-based and tab-separated output with no headings and dashes. This format makes it easy to consume the output into other commands and tools that need to process the text in some form. Using the preceding example with the `tsv` option outputs the tab-separated result. - -```azurecli-interactive -az vm list --out tsv -``` - -``` -None None /subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/DEMORG1/providers/Microsoft.Compute/virtualMachines/DemoVM010 None None westus DemoVM010 None Succeeded DEMORG1 None Microsoft.Compute/virtualMachines cbd56d9b-9340-44bc-a722-25f15b578444 -None None /subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/DEMORG1/providers/Microsoft.Compute/virtualMachines/demovm212 None None westus demovm212 None Succeeded DEMORG1 None Microsoft.Compute/virtualMachines 4bdac85d-c2f7-410f-9907-ca7921d930b4 -None None /subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/DEMORG1/providers/Microsoft.Compute/virtualMachines/demovm213 None None westus demovm213 None Succeeded DEMORG1 None Microsoft.Compute/virtualMachines 2131c664-221a-4b7f-9653-f6d542fbfa34 -None None /subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/RGDEMO001/providers/Microsoft.Compute/virtualMachines/KBDemo001VM None None westus KBDemo001VM None Succeeded RGDEMO001 None Microsoft.Compute/virtualMachines 14e74761-c17e-4530-a7be-9e4ff06ea74b -None None /subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/RGDEMO001/providers/Microsoft.Compute/virtualMachines/KBDemo02None None westus KBDemo020 None Succeeded RGDEMO001 None Microsoft.Compute/virtualMachinesed36baa9-9b80-48a8-b4a9-854c7a858ece -``` - -The next example shows how the `tsv` output can be piped to commands like `grep` and `cut` to further parse specific values out of the `list` output. The `grep` command selects only items that have text "RGD" in them and then the `cut` command selects only the eighth field (separated by tabs) value to show in the output. - -```azurecli -az vm list --out tsv | grep RGD | cut -f8 -``` - -``` -KBDemo001VM -KBDemo020 -``` - -## Setting the default output format - -You can use the `az configure` command to set up your environment or establish preferences such as default settings for output formats. For common use, the easiest output format default is the "table" format - select **3** when prompted for output format choices. - -``` -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 [3]: -``` \ No newline at end of file diff --git a/docs-ref-conceptual/get-started-with-azure-cli.md b/docs-ref-conceptual/get-started-with-azure-cli.md deleted file mode 100644 index ed9f52cbb..000000000 --- a/docs-ref-conceptual/get-started-with-azure-cli.md +++ /dev/null @@ -1,442 +0,0 @@ ---- -title: Get started with Azure CLI 2.0 -description: Get started with Azure CLI 2.0 on Linux, Mac, or Windows. -keywords: Azure CLI 2.0, Linux, Mac, Windows, OS X, Ubuntu, Debian, CentOS, RHEL, SUSE, CoreOS, Docker, Windows, Python, PIP -author: rloutlaw -ms.author: routlaw -manager: douge -ms.date: 02/27/2017 -ms.topic: article -ms.prod: azure -ms.technology: azure -ms.devlang: azurecli -ms.service: multiple -ms.assetid: 85c418a8-6177-4833-bb8d-ff4ce2233c1a ---- - -# Get started with Azure CLI 2.0 - -The Azure CLI 2.0 is Azure's new command line experience for managing Azure resources. -You can use it in your browser with [Azure Cloud Shell](/azure/cloud-shell/overview), -or you can [install](install-azure-cli.md) it on macOS, Linux, and Windows and run it from the command line. - -Azure CLI 2.0 is optimized for managing and administering Azure resources from the command line, -and for building automation scripts that work against the Azure Resource Manager. -This article helps get you started using it, and teaches you the core concepts behind it. - -For information about the latest release, see the [release notes](release-notes-azure-cli.md). - -## Connect - -The simplest way to get started is to [launch Cloud Shell](/azure/cloud-shell/quickstart). - -1. Launch Cloud Shell from the top navigation of the Azure portal. - - ![Shell icon](media/get-started-with-azure-cli/shell-icon.png) - -2. Choose the subscription you want to use and create a storage account. - - ![Create a storage account](media/get-started-with-azure-cli/storage-prompt.png) - -You can also [install](install-azure-cli.md) the CLI and run it locally from the command line. Once you have installed the CLI, -run `az login` to log in with your default subscription. - -## Create a Resource Group - -Now that we've got everything set up, let's use the Azure CLI to create resources within Azure. - -First, create a Resource Group. Resource Groups in Azure provide a way to manage multiple resources that you -want to logically group. For example, you might create a Resource Group for an application or project -and add a virtual machine, a database and a CDN service within it. - -Let's create a resource group named "MyResourceGroup" in the *westus2* region of Azure. To do so type the following command: - -```azurecli-interactive -az group create -n MyResourceGroup -l westus2 -``` - -Once the resource group has been created, the `az group create` command outputs several properties of the newly created resource: - -```Output -{ - "id": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/MyResourceGroup", - "location": "westus2", - "managedBy": null, - "name": "MyResourceGroup", - "properties": { - "provisioningState": "Succeeded" - }, - "tags": null -} -``` - -## Create a Linux Virtual Machine - -Now that we have our resource group, let's create a Linux VM within it. - -You can create a Linux VM using the popular UbuntuLTS image, with two attached storage disks of 10 GB and 20 GB, with the following command: - -```azurecli-interactive -az vm create -n MyLinuxVM -g MyResourceGroup --image UbuntuLTS --data-disk-sizes-gb 10 20 -``` - -When you run the preceding command, the Azure CLI 2.0 looks for an SSH key pair stored under your ~/.ssh directory. If you don't already have an SSH key pair stored there, you can ask the Azure CLI to automatically create one for you by passing the --generate-ssh-keys parameter: - -```azurecli-interactive -az vm create -n MyLinuxVM -g MyResourceGroup --image UbuntuLTS --data-disk-sizes-gb 10 20 --generate-ssh-keys -``` - -The `az vm create` command returns output once the VM has been fully created and is ready to be accessed and used. The output includes several properties of the newly created VM including its public IP address: - -```Output -{ - "fqdns": "", - "id": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/virtualMachines/MyLinuxVM", - "location": "westus2", - "macAddress": "xx-xx-xx-xx-xx-xx", - "powerState": "VM running", - "privateIpAddress": "xx.x.x.x", - "publicIpAddress": "xx.xxx.xxx.xx", - "resourceGroup": "MyResourceGroup" -} -``` - -Now that the VM has been created, you can log on to your new Linux VM using **SSH** with the public IP address of the VM you created: - -```azurecli-interactive -ssh xx.xxx.xxx.xxx -``` - -```Output -Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 3.19.0-65-generic x86_64) - - * Documentation: https://help.ubuntu.com/ - - System information as of Sun Feb 19 00:32:28 UTC 2017 - - System load: 0.31 Memory usage: 3% Processes: 89 - Usage of /: 39.6% of 1.94GB Swap usage: 0% Users logged in: 0 - - Graph this data and manage this system at: - https://landscape.canonical.com/ - - Get cloud support with Ubuntu Advantage Cloud Guest: - http://www.ubuntu.com/business/services/cloud - -0 packages can be updated. -0 updates are security updates. - - - -The programs included with the Ubuntu system are free software; -the exact distribution terms for each program are described in the -individual files in /usr/share/doc/*/copyright. - -Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by -applicable law. - -my-login@MyLinuxVM:~$ -``` - -## Create a Windows Server Virtual Machine - -Let's now create a Windows Server 2016 Datacenter-based VM using the `az vm create` command and add it to the same "MyResourceGroup" resource group that we used for our Linux VM. Like the Linux VM example, we'll also attach two storage disks using the `--data-disk-sizes-gb` parameter. - -Azure requires that you avoid using easily guessed usernames/passwords. There are specific rules for what characters can be used as well as the minimum length of both username and password. - -> [!NOTE] -> You will be prompted to enter your username and password when running this command. - -```azurecli-interactive -az vm create -n MyWinVM -g MyResourceGroup --image Win2016Datacenter -``` - -The `az vm create` command output results once the VM has been fully created and is ready to be accessed and used. - -```Output -{ - "fqdns": "", - "id": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/virtualMachines/MyWinVM", - "location": "westus2", - "macAddress": "xx-xx-xx-xx-xx-xx", - "powerState": "VM running", - "privateIpAddress": "xx.x.x.x", - "publicIpAddress": "xx.xxx.xx.xxx", - "resourceGroup": "MyResourceGroup" -} -``` - -Now log on to your newly created Windows Server VM using Remote Desktop and the public IP address of the VM (which is returned in the output from `az vm create`). -If you are on a Windows-based system, you can do this from the command line using the `mstsc` command: - -```azurecli-interactive -mstsc /v:xx.xxx.xx.xxx -``` - -Supply the same username/password combination you used when creating the VM to log in. - -## Creating other resources in Azure - -We've now walked through how to create a Resource Group, a Linux VM, and a Windows Server VM. You can create many other types of Azure resources as well. - -All new resources are created using a consistent `az create` naming pattern. For example, to create an Azure Network Load Balancer that we could then associate with our newly created VMs, we can use the following create command: - -```azurecli-interactive -az network lb create -n MyLoadBalancer -g MyResourceGroup -``` - -We could also create a new private Virtual Network (commonly referred to as a "VNet" within Azure) for our infrastructure using the following create command: - -```azurecli-interactive -az network vnet create -n MyVirtualNetwork -g MyResourceGroup --address-prefix 10.0.0.0/16 -``` - -What makes Azure and the Azure CLI powerful is that we can use it not just to get cloud-based infrastructure but also to -create managed platform services. The managed platform services can also be combined with infrastructure to build even more powerful solutions. - -For example, you can use the Azure CLI to create an Azure AppService. Azure AppService is a managed platform service that provides a great way to host web apps without having to worry about infrastructure. After creating the Azure AppService, you can create two new Azure Web Apps within the AppService using the following create commands: - -```azurecli-interactive -# Create an Azure AppService that we can host any number of web apps within -az appservice plan create -n MyAppServicePlan -g MyResourceGroup - -# Create Two Web Apps within the AppService (note: name param must be a unique DNS entry) -az webapp create -n MyWebApp43432 -g MyResourceGroup --plan MyAppServicePlan -az webapp create -n MyWebApp43433 -g MyResourceGroup --plan MyAppServicePlan -``` - -Once you understand the basics of the `az create` pattern, it becomes easy to create anything. Following are -some popular Azure resource types and the corresponding Azure CLI create commands to create them: - -``` -Resource Type Azure CLI create command -------------- ------------------------ -Resource Group az group create -Virtual Machine az vm create -Virtual Network az network vnet create -Load Balancer az network lb create -Managed Disk az disk create -Storage account az storage account create -Virtual Machine Scale Set az vmss create -Azure Container Service az acs create -Web App az webapp create -SQL Database Server az sql server create -Document DB az documentdb create -``` - -Visit the [Reference documentation](/cli/azure) to learn more about the additional resource-specific parameters that you can pass to each of the preceding commands and the resource types you can create. - -## Useful tip: Optimizing create operations using --no-wait - -By default when you create resources using the Azure CLI 2.0, the `az create` command waits until the -resource has been created and is ready for you to use. For example, if you create a VM, the `az vm create` command will, by default, -not return until the VM is created and is ready for you to SSH or RDP into it. - -We use this approach because it makes it easier to write automation scripts that contain multiple steps with dependencies (and need a prior task to have completed successfully before continuing). - -If you do not need to wait on creation of a resource before continuing, you can use the `no-wait` option to start -a create action in the background. You can continue using the CLI for other commands. - -For example, the following usage of the `az vm create` starts a VM deployment and then return much more quickly (and before the VM -has fully booted): - -```azurecli-interactive -az vm create -n MyLinuxVM2 -g MyResourceGroup --image UbuntuLTS --no-wait -``` - -Using the `--no-wait` approach can help you optimize the performance of your automation scripts considerably. - -## Listing resources and formatting output - -You can use the `list` command within the Azure CLI to find and list the resources running in Azure. - -Like with the create command, you can list resources using the Azure CLI 2.0 using a common `az list` naming pattern that is consistent across all resource types. There are various output formats and query options available to filter and sort the list of resources in the way you prefer to see them. - -For example, `az vm list` shows the list of all VMs you have. - -```azurecli-interactive -az vm list -``` -The values returned are by default in JSON (only showing partial output for sake of brevity). - -```json -[ - { - "availabilitySet": null, - "diagnosticsProfile": null, - "hardwareProfile": { - "vmSize": "Standard_DS1_v2" - }, - "id": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/DEMORG1/providers/Microsoft.Compute/virtualMachines/DemoVM010", - "instanceView": null, - "licenseType": null, - "location": "westus2", - "name": "MyLinuxVM", - "networkProfile": { - "networkInterfaces": [ - { - "id": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/demorg1/providers/Microsoft.Network/networkInterfaces/DemoVM010VMNic", - "primary": null, - "resourceGroup": "MyResourceGroup" - } - ] - }, - ... - ... - ... -] -``` - -You can optionally modify the output format using the `--output` option. Run the `az vm list` command to see both the Linux and Windows Server VMs created earlier, along with the most common properties of a VM, using the easy to read *table* format option: - -```azurecli-interactive -az vm list --output table -``` - -```Output -Name ResourceGroup Location ---------- --------------- ---------- -MyLinuxVM MyResourceGroup westus2 -MyWinVM MyResourceGroup westus2 -``` - -The *tsv* output option can be used to get a text-based, tab-separated format without any headers. This format is useful when you -want to pipe the output into another text-based tool like grep. - -```azurecli-interactive -az vm list --output tsv -``` - -``` -None None /subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/virtualMachines/MyLinuxVM None None westus2 MyLinuxVM None Succeeded MyResourceGroup None Microsoft.Compute/virtualMachines XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX -None None /subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/virtualMachines/MyWinVM None None westus2 MyWinVM None Succeeded MyResourceGroup None Microsoft.Compute/virtualMachines XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX -``` -Visit the [output formats](format-output-azure-cli.md) article to learn more about the additional ways to list resources and format the output. - -## Querying resources and shaping outputs - -Often you want to be able to query for only those resources that meet a specific condition. - -The `list` command has built-in support -that makes it easy to filter resources by Resource Group name. For example, you can pass either a `--ResourceGroup` or `-g` parameter -to a `list` command to only retrieve those resources within a specific resource group: - - -```azurecli-interactive -az vm list -g MyResourceGroup --output table -``` - -```Output -Name ResourceGroup Location ---------- --------------- ---------- -MyLinuxVM MyResourceGroup westus2 -MyWinVM MyResourceGroup westus2 -``` - -For even more powerful querying support, you can use the `--query` parameter to execute -a JMESPath query on the results of *any* `az` command. JMESPath queries can be used both to filter as well -as shape the output of any returned result. - -For example, execute the following command to query for any VM resource within any resource group that contains the letters "My": - -```azurecli-interactive -az vm list --output table --query "[?contains(resourceGroup, 'MY')]" -``` - -```Output -ResourceGroup ProvisioningState Name Location VmId ---------------- ------------------- --------- ---------- ------------------------------------ -MYRESOURCEGROUP Succeeded MyLinuxVM westus2 XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX -MYRESOURCEGROUP Succeeded MyWinVM westus2 XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX -``` - -We could then choose to further refine the output by using the shaping capability of JMESPath queries to output different values -as well. For example, the following command retrieves the type of OS disk the VM is using to determine whether the OS is Linux or Windows based: - -```azurecli-interactive -az vm list --output table --query "[?contains(resourceGroup, 'MY')].{ VMName:name, OSType:storageProfile.osDisk.osType }" -``` - -```Output -VMName OSType ---------- -------- -MyLinuxVM Linux -MyWinVM Windows -``` - -The JMESPath support in Azure CLI is powerful. Learn more about how to use it in our [query](query-azure-cli.md) article. - -## Deleting resources - -You can use the `delete` command within Azure CLI to delete the resources you no longer need. You can use the `delete` command with -any resource just like you can with the `create` command. - -```azurecli-interactive -az vm delete -n MyLinuxVM -g MyResourceGroup -``` - -By default the CLI prompts to confirm deletion. You can suppress this prompt for automated scripts. - -```Output -Are you sure you want to perform this operation? (y/n): y -EndTime Name StartTime Status --------------------------------- ------------------------------------ -------------------------------- --------- -2017-02-19T02:35:56.678905+00:00 5b74ab80-9b29-4329-b483-52b406583e2f 2017-02-19T02:33:35.372769+00:00 Succeeded -``` - -You can also use the `delete` command to delete many resources at a time. For example, the following command deletes all the -resources in the "MyResourceGroup" resource group that we've used for all the samples in this Get Started tutorial. - -```azurecli-interactive -az group delete -n MyResourceGroup -``` - -```Output -Are you sure you want to perform this operation? (y/n): y -``` - -## Get samples - -To learn more about ways to use the Azure CLI, check out our most common scripts for -[Linux VMs](/azure/virtual-machines/virtual-machines-linux-cli-samples?toc=%2fcli%2fazure%2ftoc.json&bc=%2fcli%2fazure%2fbreadcrumb%2ftoc.json), -[Windows VMs](/azure/virtual-machines/virtual-machines-windows-cli-samples?toc=%2fcli%2fazure%2ftoc.json&bc=%2fcli%2fazure%2fbreadcrumb%2ftoc.json), -[Web apps](/azure/app-service-web/app-service-cli-samples?toc=%2fcli%2fazure%2ftoc.json&bc=%2fcli%2fazure%2fbreadcrumb%2ftoc.json), -and [SQL Database](/azure/sql-database/sql-database-cli-samples?toc=%2fcli%2fazure%2ftoc.json&bc=%2fcli%2fazure%2fbreadcrumb%2ftoc.json). - -## Read the API reference docs - -[API reference](/cli/azure) - -## Get help - -The Azure CLI has built-in help documentation, which matches our web documentation that you can run from the command line: - -```azurecli-interactive -az [command-group [command]] -h -``` - -For example, to see what commands and subgroups are available for VMs, use: - -```azurecli-interactive -az vm -h -``` - -To get help with the command to create a VM, use: - -```azurecli-interactive -az vm create -h -``` - -## Switch from Azure CLI 1.0 - -If you already know how to use Azure CLI 1.0 (azure.js), -you'll notice places where the commands aren't quite the same. -Sometimes the commands to perform a task are significantly different. -To help you make the switch from Azure CLI 1.0 to Azure CLI 2.0, -we've started this [command mapping](https://github.com/Azure/azure-cli/blob/master/doc/azure2az_commands.rst). - -## Send us your feedback - -```azurecli-interactive -az feedback -``` diff --git a/docs-ref-conceptual/install-azure-cli.md b/docs-ref-conceptual/install-azure-cli.md deleted file mode 100644 index af3bc138b..000000000 --- a/docs-ref-conceptual/install-azure-cli.md +++ /dev/null @@ -1,507 +0,0 @@ ---- -title: Install the Azure CLI 2.0 -description: Reference docs for the installation of Azure CLI 2.0 -keywords: Azure CLI,Install Azure CLI,Azure Python CLI,Azure CLI Reference -author: sptramer -ms.author: sttramer -manager: routlaw -ms.date: 11/01/2017 -ms.topic: article -ms.prod: azure -ms.technology: azure -ms.devlang: azurecli -ms.service: multiple -ms.assetid: ea5c0ee1-c530-4a1e-a83f-e1be71f6d416 -experiment_id: 83e72847-fad8-4c -experimental: true ---- - -# Install Azure CLI 2.0 - -Install the new version of the Azure CLI today! -We've improved and updated it to provide a great native command-line experience for managing Azure resources. -It can be used on macOS, Linux, and Windows. -For information about the latest release, see the [release notes](release-notes-azure-cli.md). - -> [!NOTE] -> If you are using the Azure Service Management (ASM) model, [install Azure CLI 1.0](/azure/cli-install-nodejs). - -## Install on macOS - -On macOS, you are able to install either with [Homebrew](https://brew.sh/) or manually. - -### Install with Homebrew - -1. If you don't have it already, install Homebrew by following the [Homebrew installation instructions](https://docs.brew.sh/Installation.html). - -2. If you have previously installed the CLI manually, follow the [manual uninstall](#UninstallManually) instructions. - -3. Update your local Homebrew repositories. - - ```bash - brew update - ``` - -4. Install the `azure-cli` package. - - ```bash - brew install azure-cli - ``` - -> [!NOTE] -> If you previously installed the Azure CLI 1.0 with Homebrew, instead of installing -> the package you can get CLI 2.0 through the regular Homebrew upgrade process. -> -> ```bash -> brew upgrade -> ``` - -### Install manually - -1. Install Azure CLI 2.0 with `curl`. - - ```bash - curl -L https://aka.ms/InstallAzureCli | bash - ``` - -2. You may have to restart your shell for some changes to take effect. - - ```bash - exec -l $SHELL - ``` - -3. Run the CLI from the command prompt with the `az` command. - -## Install on Windows - -### Install with MSI for the Windows command-line - -To install the CLI on Windows and use it in the Windows command-line, download and run the [Azure CLI Installer (MSI)](https://aka.ms/InstallAzureCliWindows). - -### Install with apt-get for Bash on Ubuntu on Windows - -1. If you don't have Bash on Windows, [install it](https://msdn.microsoft.com/commandline/wsl/install_guide). - -2. Open the Bash shell. - -3. Modify your sources list. - - ```bash - echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ wheezy main" | \ - sudo tee /etc/apt/sources.list.d/azure-cli.list - ``` - -4. Run the following sudo commands: - - ```bash - sudo apt-key adv --keyserver packages.microsoft.com --recv-keys 52E16F86FEE04B979B07E28DB02C46DF417A0893 - sudo apt-get install apt-transport-https - sudo apt-get update && sudo apt-get install azure-cli - ``` - -5. Run the CLI from the command prompt with the `az` command. - -## Install with apt package manager - -For distributions using the `apt` package manager such as Ubuntu or Debian, you can install Azure CLI 2.0 via `apt-get`. - -[!INCLUDE [linux-install-requirements.md](includes/linux-install-requirements.md)] - -1. Modify your sources list: - - - 32-bit system - - ```bash - echo "deb https://packages.microsoft.com/repos/azure-cli/ wheezy main" | \ - sudo tee /etc/apt/sources.list.d/azure-cli.list - ``` - - - 64-bit system - - ```bash - echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ wheezy main" | \ - sudo tee /etc/apt/sources.list.d/azure-cli.list - ``` - -2. Run the following sudo commands: - - ```bash - sudo apt-key adv --keyserver packages.microsoft.com --recv-keys 52E16F86FEE04B979B07E28DB02C46DF417A0893 - sudo apt-get install apt-transport-https - sudo apt-get update && sudo apt-get install azure-cli - ``` - -3. Run the CLI from the command prompt with the `az` command. - -## Install with yum package manager - -For distributions which use the `yum` package manager such as Red Hat Enterprise Linux (RHEL), Fedora, or CentOS, you can install Azure CLI 2.0 via `yum`. - -[!INCLUDE [linux-install-requirements.md](includes/linux-install-requirements.md)] - -1. Import the Microsoft repository key: - - ```bash - sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc - ``` - -2. Create local `azure-cli` repository information: - - ```bash - sudo sh -c 'echo -e "[azure-cli]\nname=Azure CLI\nbaseurl=https://packages.microsoft.com/yumrepos/azure-cli\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/azure-cli.repo' - ``` - -3. Update the `yum` package index and install: - - ```bash - yum check-update - sudo yum install azure-cli - ``` - -4. Run the CLI from the command prompt with the `az` command. - -## Install with zypper package manager - -For distributions which use the `zypper` package manager such as OpenSUSE or SLE, you can install Azure CLI 2.0 via `zypper`. - -[!INCLUDE [linux-install-requirements.md](includes/linux-install-requirements.md)] - -1. Import the Microsoft repository key: - - ```bash - sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc - ``` - -2. Create local `azure-cli` repository information: - - ```bash - sudo sh -c 'echo -e "[azure-cli]\nname=Azure CLI\nbaseurl=https://packages.microsoft.com/yumrepos/azure-cli\nenabled=1\ntype=rpm-md\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/zypp/repos.d/azure-cli.repo' - ``` - -3. Update the `zypper` package index and install: - - ```bash - sudo zypper refresh - sudo zypper install azure-cli - ``` - -4. Run the CLI from the command prompt with the `az` command. - -## Install with Docker - -We maintain a Docker image preconfigured with the Azure CLI 2.0. - -Install the CLI using `docker run`. - - ```bash - docker run -it azuresdk/azure-cli-python: - ``` - -See our [Docker tags](https://hub.docker.com/r/azuresdk/azure-cli-python/tags/) for available versions. - -The CLI is installed on the image as the `az` command in `/usr/local/bin`. - -> [!NOTE] -> If you want to pick up the SSH keys from your user environment, -> you can use `-v ${HOME}:/root` to mount $HOME as `/root`. - -> ```bash -> docker run -it -v ${HOME}:/root azuresdk/azure-cli-python: -> ``` - -## Install on Linux without a package manager - -It is recommended that you install the CLI with a package manager if you are able to. If you do not want to add Microsoft's repositories, or are working with -a distribution which does not have a provided package, you can manually install the CLI. - -1. Install the prerequisites based on your Linux distribution. - - ``` - Platform | Prerequisites - ----------------------|--------------------------------------------- - Ubuntu 15.10 or 16.04 | sudo apt-get update && sudo apt-get install -y python libssl-dev libffi-dev python-dev build-essential - Ubuntu 12.04 or 14.04 | sudo apt-get update && sudo apt-get install -y python libssl-dev libffi-dev python-dev - Debian 8 | sudo apt-get update && sudo apt-get install -y python libssl-dev libffi-dev python-dev build-essential - Debian 7 | sudo apt-get update && sudo apt-get install -y python libssl-dev libffi-dev python-dev - CentOS 7.1 or 7.2 | sudo yum check-update; sudo yum install -y gcc python libffi-devel python-devel openssl-devel - RedHat 7.2 | sudo yum check-update; sudo yum install -y gcc python libffi-devel python-devel openssl-devel - SUSE OpenSUSE 13.2 | sudo zypper refresh && sudo zypper --non-interactive install curl gcc python python-xml libffi-devel python-devel openssl-devel - ``` - -If your distribution is not listed above, you will need to install [Python 2.7 or later](https://www.python.org/downloads/), [libffi](https://sourceware.org/libffi/), and [OpenSSL 1.0.2](https://www.openssl.org/source/). - -2. Install the CLI with `curl`. - - ```bash - curl -L https://aka.ms/InstallAzureCli | bash - ``` - -3. You may have to restart your shell for some changes to take effect. - - ```bash - exec -l $SHELL - ``` - -4. Run the CLI from the command prompt with the `az` command. - -## Troubleshooting - -If you encounter an issue during CLI install, check this section to see if your particular case is covered. If your issue is not here, please [file a Github issue](https://github.com/Azure/azure-cli/issues). - -### curl "Object Moved" error - -If you get an error from `curl` related to the `-L` parameter, or an error message including the text "Object Moved", try using the full URL instead of the `aka.ms` redirect: - -```bash -curl https://azurecliprod.blob.core.windows.net/install | bash -``` - -### `az` command not found - -You may need to clear your shell's command hash cache. Run - -```bash -hash -r -``` - -and see if the problem is resolved. The command may also not be in your `$PATH`. Make sure that `/bin` appears in your `$PATH`, and restart your shell if necessary. - -## Uninstall CLI 1.x versions - -If you have an earlier CLI 1.x version available on your system, you can uninstall it based upon the type of install used. - -### Uninstall with npm - -Remove the older CLI with `npm uninstall`. - - ```bash - npm uninstall -g azure-cli - ``` - -### Uninstall with distributable - -If you installed via the [Azure CLI Installer (MSI)](http://aka.ms/webpi-azure-cli) or a [macOS package](http://aka.ms/mac-azure-cli), use the same tool to remove your install. - -### Uninstall with Docker - -If you installed a Docker image to use the earlier CLI version, remove that image and any associated containers. You can then re-create the containers -after installing the new Docker image as described in the install instructions. - - ```bash - docker rmi -f microsoft/azure-cli - ``` - -## Update the CLI - -To update the Azure CLI, use the same method that you used to install it. - -### Update with Homebrew - -1. If you previously installed manually, follow the [install with Homebrew](#macOS) instructions. - -2. Update your local Homebrew repository information. - - ```bash - brew update - ``` - -3. Upgrade your installed packages. - - ```bash - brew upgrade - ``` - -### Update with MSI - -Run the [Azure CLI Installer (MSI)](https://aka.ms/InstallAzureCliWindows) again. - -### Update with apt - -Use `apt-get upgrade` to update the CLI package. - - ```bash - sudo apt-get update && sudo apt-get upgrade - ``` - -> [!NOTE] -> This will upgrade all of the installed packages on your system which have not had a dependency change. -> To upgrade only the CLI, use `apt-get install`. -> ```bash -> sudo apt-get update && sudo apt-get install --only-upgrade -y azure-cli -> ``` - -### Update with yum - -Update the Azure CLI with the `yum update` command. - -```bash -yum check-update -sudo yum update azure-cli -``` - -### Update with zypper - -You can update the package with the `zypper update` command. - -```bash -sudo zypper refresh -sudo zypper update azure-cli -``` - -### Update with Docker - -1. Update your local image with `docker pull`. - - ```bash - docker pull azuresdk/azure-cli-python - ``` - -2. Get the containers currently using the CLI image. - - ```bash - docker container ls -a --filter 'ancestor=azuresdk/azure-cli-python' - ``` - - ```output - CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES - 34a868beb2ab azuresdk/azure-cli-python:latest "/bin/sh -c bash" 8 minutes ago Exited (0) 8 minutes ago inspiring_benz - ``` - -> [!NOTE] -> If you installed a specific version of the image, you will need to add `:` to the end of the image name. - -3. Halt and recreate the containers. - - ```bash - docker stop inspiring_benz - docker rm inspiring_benz - docker run azuresdk/azure-cli-python - ``` - -### Update manually - -Follow the manual installation instructions for [macOS](#macOS) or [Linux](#Linux) to update. - -## Uninstall - -If you decide to uninstall the CLI, we're sorry to see you go. You should uninstall using the same method that you used to install the CLI. - -### Uninstall with Homebrew - -Uninstall the `azure-cli` package. - - ```bash - brew uninstall azure-cli - ``` - -### Uninstall with MSI - -Run the [MSI](https://aka.ms/InstallAzureCliWindows) again and choose uninstall. - -### Uninstall with apt - -Uninstall via `apt-get remove`: - - ```bash - sudo apt-get remove -y azure-cli - ``` - -### Uninstall with yum - -1. Remove the package from your system. - - ```bash - sudo yum remove azure-cli - ``` - -2. If you do not plan to reinstall the CLI, remove the repository information. - - ```bash - sudo rm /etc/yum.repos.d/azure-cli.repo - ``` - -3. If you removed the repository information, also remove the Microsoft GPG signature key. - - ```bash - MSFT_KEY=`rpm -qa gpg-pubkey /* --qf "%{version}-%{release} %{summary}\n" | grep Microsoft | awk '{print $1}'` - rpm -e --allmatches gpg-pubkey-$MSFT_KEY - ``` - -### Uninstall with zypper - -1. Remove the package from your system. - - ```bash - sudo zypper remove -y azure-cli - ``` - -2. If you do not plan to reinstall the CLI, remove the repository information. - - ```bash - sudo rm /etc/zypp/repos.d/azure-cli.repo - ``` - -3. If you removed the repository information, also remove the Microsoft GPG signature key. - - ```bash - MSFT_KEY=`rpm -qa gpg-pubkey /* --qf "%{version}-%{release} %{summary}\n" | grep Microsoft | awk '{print $1}'` - rpm -e --allmatches gpg-pubkey-$MSFT_KEY - ``` - -### Uninstall with Docker - -If you installed a docker image, you will need to remove any containers running it, and then delete the local image. - -1. Get the containers which are running the azure-cli image. - - ```bash - docker container ls -a --filter 'ancestor=azuresdk/azure-cli-python' - ``` - - ```output - CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES - 34a868beb2ab azuresdk/azure-cli-python:latest "/bin/sh -c bash" 8 minutes ago Exited (0) 8 minutes ago inspiring_benz - ``` - -2. Delete any containers with the CLI image. - - ```bash - docker rm 34a868beb2ab - ``` - -3. Remove the locally installed CLI image. - - ```bash - docker rmi azuresdk/azure-cli-python - ``` - -> [!NOTE] -> If you installed a specific version of the image, you will need to add `:` to the end of the image name. - -###Uninstall manually - -If you used the script at https://aka.ms/InstallAzureCli to install the CLI, you can uninstall it with these steps. - -1. Remove the installed files. - - ```bash - rm -r /lib/azure-cli - rm /bin/az - ``` - -2. Delete the line `/lib/azure-cli/az.completion` from `/.bash_profile`. - -3. If your shell uses a command cache, reload it. - - ```bash - hash -r - ``` - -> [!Note] -> The default install location is `/Users/` for macOS and `/home/` for Linux. - -## Report CLI issues and feedback - -If you encounter any bugs with the tool, -file an issue in the [Issues](https://github.com/Azure/azure-cli/issues) section of our GitHub repository. -To provide feedback from the command line, use the `az feedback` command. diff --git a/docs-ref-conceptual/interactive-azure-cli.md b/docs-ref-conceptual/interactive-azure-cli.md deleted file mode 100644 index a35d22b59..000000000 --- a/docs-ref-conceptual/interactive-azure-cli.md +++ /dev/null @@ -1,121 +0,0 @@ ---- -title: Azure CLI 2.0 Interactive Mode -description: Use Azure CLI 2.0 in interactive mode. -keywords: Azure CLI 2.0, interactive mode -author: rloutlaw -ms.author: routlaw -manager: douge -ms.date: 04/06/2017 -ms.topic: article -ms.prod: azure -ms.technology: azure -ms.devlang: azurecli -ms.service: multiple -ms.assetid: ---- - -# Interactive Azure CLI 2.0 - -You can use Azure CLI 2.0 in interactive mode by running the `az interactive` command. -That places you in an interactive shell where your commands are auto-completed -and you have access to descriptions of commands and their parameters and command examples. - -![interactive mode](./media/interactive-azure-cli/webapp-create.png) - -> [!NOTE] -> We're not using the default style here, which doesn't read as well on a black background. - -If you're not already logged in to your account, use the `login` command to do that. - -## Configure - -Interactive mode optionally displays command descriptions, parameter descriptions, and command examples. -You can turn descriptions and examples on or off using `F1`. - -![descriptions and examples](./media/interactive-azure-cli/descriptions-and-examples.png) - -You can turn the display of parameter defaults on or off using `F2`. - -![defaults](./media/interactive-azure-cli/defaults.png) - -`F3` toggles the display of some key gestures. - -![gestures](./media/interactive-azure-cli/gestures.png) - -## Scope - -You can scope your interactive mode to a specific command group like `vm` or `vm image`. -When you do, all commands are interpreted in that scope. -It's a great shorthand if you're doing all your work in that command group. - -Instead of typing these commands: - -```azurecli -az>> vm create -n myVM -g myRG --image UbuntuLTS -az>> vm list -o table -``` - -You can scope to the vm command group and type these commands: - -```azurecli -az>> %%vm -az vm>> create -n myVM -g myRG --image UbuntuLTS -az vm>>list -o table -``` - -You can scope to lower-level command groups as well. -You could scope to `vm image` using `%%vm image`. -In this case, since we're already scoped to `vm`, we would use `%%image`. - -```azurecli -az vm>> %%image -az vm image>> -``` - -At that point, we can pop the scope back up to `vm` using `%%..`, -or we can scope to the root with just `%%`. - -```azurecli -az vm image>> %% -az>> -``` - -## Query - -You can execute a JMESPath query on the results of the last command that you executed. -For example, after you create a VM, you can make sure it has fully provisioned. - -```azurecli -az>> vm create --name myVM --resource-group myRG --image UbuntuLTS --no-wait -az>> ? [*].provisioningState -``` - -``` -[ - "Creating" -] -``` - -To learn more about querying the results of your commands, -see [Query command results with Azure 2.0](query-azure-cli.md). - -## Bash commands - -You can run shell commands without leaving interactive mode using `#[cmd]`. - -```azurecli -az>> #dir -``` - -## Examples - -Some commands have lots of examples. -You can scroll to the next page of examples using `CTRL-N` and the previous page using `CTRL-Y`. - -![examples](./media/interactive-azure-cli/examples.png) - -You can also look at a specific example using `::#`. - -```azurecli -az>> vm create ::8 -``` diff --git a/docs-ref-conceptual/manage-azure-subscriptions-azure-cli.md b/docs-ref-conceptual/manage-azure-subscriptions-azure-cli.md deleted file mode 100644 index c75666096..000000000 --- a/docs-ref-conceptual/manage-azure-subscriptions-azure-cli.md +++ /dev/null @@ -1,60 +0,0 @@ ---- -title: Manage Azure subscriptions with Azure CLI 2.0 -description: Manage Azure subscriptions with Azure CLI 2.0 on Linux, Mac, or Windows. -keywords: Azure CLI 2.0, Linux, Mac, Windows, OS X, subscription -author: kamaljit -ms.author: sttramer -manager: routlaw -ms.date: 10/30/2017 -ms.topic: article -ms.prod: azure -ms.technology: azure -ms.devlang: azurecli -ms.service: multiple -ms.assetid: 98fb955e-6dbf-47e2-80ac-170d6d95cb70 ---- - -# Manage multiple Azure subscriptions - -Most Azure users will only ever have a single subscription. However, if you are part of multiple organizations or your organization has -divided up access to certain resources across groupings, you may have multiple subscriptions within Azure. Multiple subscriptions can -be easily managed with the CLI, and operations can be performed by selecting a subscription. - -## Tenants, users, and subscriptions - -You might have some confusion over the difference between tenants, users, and subscriptions within Azure. In general, a _tenant_ is the Azure Active Directory -entity which encompasses a whole organization. This tenant has at least one _subscription_ and _user_. A user is an individual, and is associated with only -one tenant, the organization that they belong to. Users are those accounts which log in to Azure to provision and use resources. A user may have access to multiple _subscriptions_, -which are the agreements with Microsoft to use cloud services, including Azure. Every resource is associated with a subscription. - -To learn more about the differences between tenants, users, and subscriptions, see the [Azure cloud terminology dictionary](/azure/azure-glossary-cloud-terminology). -To learn how to add a new subscription to your Azure Active Directory tenant, see [How to add an Azure subscription to Azure Active Directory](/azure/active-directory/active-directory-how-subscriptions-associated-directory). - -## Working with multiple subscriptions - -To access the resources contained within a subscription, you need to switch your active subscription. All work with subscriptions is done through the `az account` command, which -refers to the service agreement that a subscription represents and not your individual account. - -[!INCLUDE [cloud-shell-try-it.md](includes/cloud-shell-try-it.md)] - -To start working with your available subscriptions, get a list of those available in your account: - -```azurecli-interactive -az account list --output table -``` - -```Output -Name CloudName SubscriptionId State IsDefault -------------------------------------------- ----------- ------------------------------------ -------- ----------- -My Production Subscription AzureCloud XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX Enabled -My DevTest Subscription AzureCloud XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX Enabled True -My Demos AzureCloud XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX Enabled -``` - -In order to change the active subscription, you can use `az account set`: - -```azurecli-interactive -az account set --subscription "My Demos" -``` - -You can use either the subscription ID or the subscription name to select the subscription. diff --git a/docs-ref-conceptual/overview.md b/docs-ref-conceptual/overview.md deleted file mode 100644 index f27ae2773..000000000 --- a/docs-ref-conceptual/overview.md +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: Azure CLI 2.0 -description: Overview of the Azure CLI 2.0. -keywords: Azure CLI 2.0, Linux, Mac, Windows, OS X, Ubuntu, Debian, CentOS, RHEL, SUSE, CoreOS, Docker, Windows, Python, PIP -author: rloutlaw -ms.author: routlaw -manager: douge -ms.date: 02/27/2017 -ms.topic: article -ms.prod: azure -ms.technology: azure -ms.devlang: azurecli -ms.service: multiple -ms.assetid: 80ae9f6c-adb7-483c-bfb4-fbb958e075ba ---- - -# Azure CLI 2.0 - -The Azure CLI 2.0 is Azure's new command-line experience for managing Azure resources. -You can use it in your browser with [Azure Cloud Shell](/azure/cloud-shell/overview), -or you can [install](install-azure-cli.md) it on macOS, Linux, and Windows and run it from the command line. - -Azure CLI 2.0 is optimized for managing and administering Azure resources from the command line, and for building automation scripts that work against the Azure Resource Manager. Using the Azure CLI 2.0, you can create VMs within Azure as easily as typing the following command: - -```azurecli-interactive -az vm create -n MyLinuxVM -g MyResourceGroup --image UbuntuLTS -``` - -Use the [Cloud Shell](/azure/cloud-shell/overview) to run the CLI in your browser, -or [install](install-azure-cli.md) it on macOS, Linux, or Windows. -Read the [Get Started](get-started-with-azure-cli.md) article to begin using the CLI. -For information about the latest release, see the [release notes](release-notes-azure-cli.md). - -The following samples can help you learn how to perform common scenarios with Azure CLI 2.0: -- [Linux Virtual Machines](/azure/virtual-machines/virtual-machines-linux-cli-samples?toc=%2fcli%2fazure%2ftoc.json&bc=%2fcli%2fazure%2fbreadcrumb%2ftoc.json) -- [Windows Virtual Machines](/azure/virtual-machines/virtual-machines-windows-cli-samples?toc=%2fcli%2fazure%2ftoc.json&bc=%2fcli%2fazure%2fbreadcrumb%2ftoc.json) -- [Web Apps](/azure/app-service-web/app-service-cli-samples?toc=%2fcli%2fazure%2ftoc.json&bc=%2fcli%2fazure%2fbreadcrumb%2ftoc.json) -- [SQL Database](/azure/sql-database/sql-database-cli-samples?toc=%2fcli%2fazure%2ftoc.json&bc=%2fcli%2fazure%2fbreadcrumb%2ftoc.json) - -A detailed [reference](/cli/azure/) is also available that documents how to use each individual Azure CLI 2.0 command. - -[Get started](get-started-with-azure-cli.md) with Azure CLI 2.0 now. - - -> [!NOTE] -> If you use the previous version of the CLI (Azure CLI), you can continue to use it. -> If you use both CLIs, remember that `azure` is the old CLI - Azure CLI, and that `az` is the new CLI - Azure CLI 2.0. \ No newline at end of file diff --git a/docs-ref-conceptual/query-azure-cli.md b/docs-ref-conceptual/query-azure-cli.md deleted file mode 100644 index 0035bc3e0..000000000 --- a/docs-ref-conceptual/query-azure-cli.md +++ /dev/null @@ -1,165 +0,0 @@ ---- -title: Query command results with Azure CLI 2.0 -description: Use --query to perform JMESPath queries on the output of Azure CLI 2.0 commands. -keywords: Azure CLI 2.0, JMESPath, query, Linux, Mac, Windows, OS X -author: rloutlaw -ms.author: routlaw -manager: douge -ms.date: 02/27/2017 -ms.topic: article -ms.prod: azure -ms.technology: azure -ms.devlang: azurecli -ms.service: multiple -ms.assetid: 5979acc5-21a5-41e2-a4b6-3183bfe6aa22 ---- - -# Using JMESPath queries with Azure CLI 2.0 - -The Azure CLI 2.0 uses the `--query` parameter to execute a [JMESPath query](http://jmespath.org) on the results of your `az` command. JMESPath is a powerful query language for JSON outputs. If you are unfamiliar with JMESPath queries you can find a tutorial at [JMESPath.org/tutorial](http://JMESPath.org/tutorial.html). - -`Query` parameter is supported by every resource type (Container Services, Web Apps, VM, etc.) within Azure CLI 2.0 and can be used for various different purposes. We have listed several examples below. - -## Selecting simple properties - -The simple `list` command with `table` output format returns a curated set of most common, simple properties for each resource type in an easy-to-read tabular format. - -```azurecli-interactive -az vm list --out table -``` - -``` -Name ResourceGroup Location ------------ --------------- ---------- -DemoVM010 DEMORG1 westus -demovm212 DEMORG1 westus -demovm213 DEMORG1 westus -KBDemo001VM RGDEMO001 westus -KBDemo020 RGDEMO001 westus -``` - -You can use the `--query` parameter to show just the Resource Group name and VM name for all virtual machines in your subscription. - -```azurecli-interactive -az vm list \ - --query [*].[name, resourceGroup] --out table -``` - -``` -Column1 Column2 ---------- ----------- -DemoVM010 DEMORG1 -demovm111 DEMORG1 -demovm211 DEMORG1 -demovm212 DEMORG1 -demovm213 DEMORG1 -demovm214 DEMORG1 -demovm222 DEMORG1 -KBDemo001VM RGDEMO001 -KBDemo020 RGDEMO001 -``` - -In the previous example, you notice that the column headings are "Column1" and "Column2". You can add friendly labels or names to the properties you select, as well. In the following example, we added the labels "VMName" and "RGName" to the selected properties "name" and "resourceGroup". - - -```azurecli-interactive -az vm list \ - --query "[].{RGName:resourceGroup, VMName:name}" --out table -``` - -``` -RGName VMName ---------- ----------- -DEMORG1 DemoVM010 -DEMORG1 demovm111 -DEMORG1 demovm211 -DEMORG1 demovm212 -DEMORG1 demovm213 -DEMORG1 demovm214 -DEMORG1 demovm222 -RGDEMO001 KBDemo001VM -RGDEMO001 KBDemo020 -``` - -## Selecting complex nested properties - -If the property you want to select is nested deep in the JSON output you need to supply the full path to that nested property. The following example shows how to select the VMName and the OS type from the vm list command. - -```azurecli-interactive -az vm list \ - --query "[].{VMName:name, OSType:storageProfile.osDisk.osType}" --out table -``` - -``` -VMName OSType ------------ -------- -DemoVM010 Linux -demovm111 Linux -demovm211 Linux -demovm212 Linux -demovm213 Linux -demovm214 Linux -demovm222 Linux -KBDemo001VM Linux -KBDemo020 Linux -``` - -## Filter with the contains function - -You can use the JMESPath `contains` function to refine your results returned in the query. -In the following example, the command selects only VMs that have the text "RGD" in their name. - -```azurecli-interactive -az vm list \ - --query "[?contains(resourceGroup, 'RGD')].{ resource: resourceGroup, name: name }" --out table -``` - -``` -Resource VMName ----------- ----------- -RGDEMO001 KBDemo001VM -RGDEMO001 KBDemo020 -``` - -With the next example, the results will return the VMs that have the vmSize 'Standard_DS1'. - -```azurecli-interactive -az vm list \ - --query "[?contains(hardwareProfile.vmSize, 'Standard_DS1')]" --out table -``` - -``` -ResourceGroup VMName VmId Location ProvisioningState ---------------- --------- ------------------------------------ ---------- ------------------- -DEMORG1 DemoVM010 cbd56d9b-9340-44bc-a722-25f15b578444 westus Succeeded -DEMORG1 demovm111 c1c024eb-3837-4075-9117-bfbc212fa7da westus Succeeded -DEMORG1 demovm211 95eda642-417f-4036-9475-67246ac0f0d0 westus Succeeded -DEMORG1 demovm212 4bdac85d-c2f7-410f-9907-ca7921d930b4 westus Succeeded -DEMORG1 demovm213 2131c664-221a-4b7f-9653-f6d542fbfa34 westus Succeeded -DEMORG1 demovm214 48f419af-d27a-4df0-87f3-9481007c2e5a westus Succeeded -DEMORG1 demovm222 e0f59516-1d69-4d54-b8a2-f6c4a5d031de westus Succeeded -``` - -## Filter with grep - -The `tsv` output format is a tab-separated text with no headers. It can be piped to commands like `grep` and `cut` to further parse specific values out of the `list` output. In the following example, the `grep` command selects only VMs that have text "RGD" in their name. The `cut` command selects only the 8th field (separated by tabs) value to show in the output. - -```azurecli-interactive -az vm list --out tsv | grep RGD | cut -f8 -``` - -``` -KBDemo001VM -KBDemo020 -``` - -## Explore with jpterm - -You can also pipe the command output to [JMESPath-terminal](https://github.com/jmespath/jmespath.terminal) -and experiment with your JMESPath query there. - -```bash -pip install jmespath-terminal -az vm list | jpterm -``` -