Azure Management Automation Client Library

1.0.0 · active · verified Thu Apr 16

The `azure-mgmt-automation` library provides Python APIs for managing Azure Automation resources, including Automation Accounts, Runbooks, Jobs, Schedules, and Hybrid Runbook Workers. It is part of the Azure SDK for Python (Track 2) and is currently at version 1.0.0. Azure SDKs typically follow an 'as-needed' release cadence, with updates when new service features or bug fixes are available.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate, create an `AutomationClient`, and perform basic operations like listing and retrieving Azure Automation accounts. It relies on environment variables for configuration and `DefaultAzureCredential` for flexible authentication.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.automation import AutomationClient

# Ensure you have your Azure Subscription ID set as an environment variable
# For example: export AZURE_SUBSCRIPTION_ID='your-subscription-id'
subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', '')
resource_group_name = 'myResourceGroup'
automation_account_name = 'myAutomationAccount'

if not subscription_id:
    raise ValueError("AZURE_SUBSCRIPTION_ID environment variable not set.")

# Authenticate using DefaultAzureCredential (supports various methods: AZURE_CLI, ENV VARS, Managed Identity, etc.)
credential = DefaultAzureCredential()

# Create an Automation client
automation_client = AutomationClient(credential, subscription_id)

try:
    # Example: List automation accounts in a resource group
    print(f"Listing automation accounts in resource group '{resource_group_name}':")
    automation_accounts = automation_client.automation_accounts.list_by_resource_group(resource_group_name)
    for account in automation_accounts:
        print(f" - {account.name} (Location: {account.location})")

    # Example: Get a specific automation account
    account = automation_client.automation_accounts.get(resource_group_name, automation_account_name)
    print(f"\nRetrieved automation account: {account.name}")

except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure the resource group and automation account exist and your credentials have permission.")

view raw JSON →