Execute Azure CLI Command
Overview
The Execute Azure CLI Command action allows users to execute Azure CLI commands directly from their bot workflow. This feature provides users with the flexibility to retrieve details about Azure resources efficiently. Users can input an Azure CLI command manually or leverage AI to generate commands based on specific needs.
Prerequisites
Linux Agent
- The Azure CLI must be installed and configured on the agent, with credentials that have the appropriate permissions for the intended Azure operations.
- Refer to the Azure CLI installation guide.
How to Use This Action?
To utilize the Execute Azure CLI Command action, follow these steps:
-
In your bot workflow, navigate to the Linux Actions and select Library.
-
Search for or locate the Execute Azure CLI Command action and drag it into your workflow.
-
Select the Linux integration that is connected to your Azure CLI-configured agent.
-
Under the Parameters section, specify the required parameter values according to your requirements. For more details, refer to the Parameter Details section.
-
In the
azure_cli_command
field, you can either:-
Manually enter the Azure CLI command you want to execute.
-
Use AI to generate the command by clicking on the "Generate with AI" button. For example, enter a prompt like "retrieve all resource groups."
-
-
Save or update the bot, then click on the Run button to execute the bot or the Run button inside the action node. Wait for the execution to complete. After execution, view the results in the execution details.
Parameter Details
Parameter | Required | Description |
---|---|---|
azure_cli_command | Yes | The Azure CLI command to execute. |
use_az_cli_profile | Conditional | Indicates whether to use the Azure CLI profile directly (defaults to False). This is a straightforward method to get started. Ensure the Azure CLI is installed and configured. For advanced options, use azure_config_profile . |
run_as_user | Yes | Specifies the user under which the command runs (defaults to "ubuntu."). Update the username if using a different cloud provider or user. Ensure Azure CLI is configured for this user. |
azure_config_profile | Conditional | The profile from which to load Azure credentials. If you want to use this instead of use_az_cli_profile , add the necessary credentials to the agent configuration file, including AZURE_CLIENT_ID , AZURE_CLIENT_SECRET , AZURE_TENANT_ID , and AZURE_SUBSCRIPTION_ID . For more information on the agent configuration file, refer to the Agent Installation Guide. |
execution_timeout | Yes | The maximum time (in seconds) allowed for command execution, defaulting to 60 seconds. |
Example Use Case
Scenario: Identifying Untagged Virtual Machines
As a cloud administrator, you need to ensure compliance with your organization's tagging policy for Azure resources. During a recent audit, you found that some virtual machines (VMs) are missing important tags, which could lead to unforeseen costs.
To address this, you want to retrieve a list of all VMs in a specific Resource Group that do not have a tag named Environment
. This will help you identify and rectify any discrepancies.
Retrieve VMs Without a Specific Tag: You will execute a command to filter and list all VMs in the MyResourceGroup
that lack the Environment
tag.
-
Command:
az vm list --resource-group MyResourceGroup --query "[?tags.Environment==null]"
This command will return a list of VMs that do not have the
Environment
tag, allowing you to take action to update their tagging and ensure compliance.