AWXKit

24.6.1 · active · verified Thu Apr 16

The official command line interface for Ansible AWX, also providing a Python API for interacting with the AWX REST API. As of July 2024, AWXKit is actively maintained, with frequent releases aligning with the AWX project's fast-moving development cadence. The latest stable release is 24.6.1.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to an AWX instance using username/password authentication and list organizations. It uses environment variables for secure credential handling.

import os
from awxkit.api import ApiV2, config
from awxkit.api.resources import resources
from awxkit.utils import PseudoNamespace

# Configure AWX host and credentials
config.base_url = os.environ.get('AWX_HOST', 'https://localhost:8043')
config.credentials = PseudoNamespace({
    'default': {
        'username': os.environ.get('AWX_USERNAME', 'admin'),
        'password': os.environ.get('AWX_PASSWORD', 'password'),
        'insecure': os.environ.get('AWX_INSECURE_SSL', 'False').lower() == 'true'
    }
})

try:
    # Load a session and get available API resources
    session_connection = ApiV2().load_session().get()
    api_resources = session_connection.get(resources)

    print(f"Successfully connected to AWX at: {config.base_url}")
    print(f"Available API resources: {list(api_resources.keys())}")

    # Example: List all organizations
    organizations = api_resources.organizations.get().results
    print(f"Found {len(organizations)} organizations:")
    for org in organizations:
        print(f" - {org.name} (ID: {org.id})")

except Exception as e:
    print(f"Error connecting to AWX: {e}")
    print("Please ensure AWX_HOST, AWX_USERNAME, AWX_PASSWORD, and AWX_INSECURE_SSL (optional) environment variables are set correctly.")

view raw JSON →