Registry / devops / ansible-tower-cli

ansible-tower-cli

JSON →
library3.3.9pypypi✓ verified 87d ago

Ansible Tower CLI (tower-cli) is a command-line interface tool for interacting with Ansible Tower and AWX instances. It allows users to manage resources like job templates, inventories, and projects directly from the terminal, and also provides a programmatic interface for Python scripts. The library is currently at version 3.3.9 and receives regular updates, typically with several minor releases focusing on bug fixes and new features throughout the year.

pip install ansible-tower-cli
INSTALL
IMPORT
SIG · ANSIBLE-TOWER-CLI
A
ansible-tower-cli
devopspythonv3.3.9
Install
3.5s avg
Import
—
Disk
25MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v3.3.9 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 26.7MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 3.5s · import 0.000s · 28MB
25MB installed
● package 25MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_resource
✓ from tower_cli import get_resource
✗ import tower_cli

This quickstart demonstrates how to use `ansible-tower-cli` programmatically within a Python script. It relies on environment variables (`TOWER_HOST`, `TOWER_TOKEN`, `TOWER_VERIFY_SSL`) for configuration, which is the recommended approach for secure and flexible scripting. It then fetches and prints the first five job templates from the configured Tower/AWX instance. Ensure you have your instance details and API token set as environment variables before running.

import os import tower_cli # Configure tower_cli using environment variables # Recommended: set TOWER_HOST and TOWER_TOKEN for secure authentication. # Example: export TOWER_HOST='https://your-awx-instance.com' # export TOWER_TOKEN='your_api_token' # export TOWER_VERIFY_SSL='False' # if using self-signed certs host = os.environ.get('TOWER_HOST', 'https://localhost') token = os.environ.get('TOWER_TOKEN', '') verify_ssl_str = os.environ.get('TOWER_VERIFY_SSL', 'True').lower() verify_ssl = verify_ssl_str == 'true' or verify_ssl_str == '1' if not token: print("WARNING: TOWER_TOKEN environment variable not set. This example will likely fail.") print("Please set TOWER_HOST and TOWER_TOKEN (and optionally TOWER_VERIFY_SSL) environment variables.") # Programmatically set configuration, this will override environment variables if set # This also persists to a config file by default, which can be useful but might be unintended. # For a single script run, relying solely on env vars is often preferred. # If you need to set explicitly in code: # tower_cli.get_resource('settings').modify( # TOWER_HOST=host, # TOWER_TOKEN=token, # TOWER_VERIFY_SSL=verify_ssl # ) print(f"Attempting to connect to Tower/AWX at: {host}") print("Listing the first 5 job templates...") try: # Using tower_cli.get_resource() to interact with the API # Configuration will be picked up from environment variables. job_templates_resource = tower_cli.get_resource('job_templates') job_templates = job_templates_resource.list(page_size=5) if job_templates: print("Successfully retrieved job templates:") for jt in job_templates: print(f"- ID: {jt['id']}, Name: {jt['name']}") else: print("No job templates found or access denied. Check your permissions and connection.") except tower_cli.exceptions.TowerCLIError as e: print(f"An error occurred while interacting with Tower/AWX: {e}") print("Please ensure your TOWER_HOST, TOWER_TOKEN, and TOWER_VERIFY_SSL environment variables are correctly set and accessible.") except Exception as e: print(f"An unexpected error occurred: {e}")
tower-cli --version
Debug
Known issues
breakingThe default behavior for `verify_ssl` changed from `False` to `True` in `v3.3.2`. If you were relying on SSL verification being off without explicitly setting it, your commands will now fail with SSL certificate errors.
fix
Explicitly set `TOWER_VERIFY_SSL=False` in your environment variables, or use `--insecure` flag on the CLI, or ensure your Python environment trusts the SSL certificate of your Tower/AWX instance.
affects: >=3.3.2
gotchaAs of `v3.3.0`, `tower-cli login` introduced token-based authentication as the recommended method. While username/password can still be used directly in some commands, using API tokens is more secure and generally preferred, especially for programmatic access.
fix
Use `tower-cli login` to obtain an API token and then set the `TOWER_TOKEN` environment variable for your CLI or programmatic interactions. Avoid embedding `--username` and `--password` directly in scripts or command lines.
affects: >=3.3.0
gotchaWhen using `tower-cli` programmatically, configurations set via `tower_cli.get_resource('settings').modify()` persist to a local configuration file by default. This can lead to unexpected behavior if multiple scripts or users share the same configuration or if you intend for settings to be transient.
fix
For transient or script-specific configurations, rely primarily on environment variables (`TOWER_HOST`, `TOWER_TOKEN`, etc.) which are picked up automatically by `tower_cli`. If you must modify settings in code, consider explicitly resetting or managing the config file location if persistence is not desired.
affects: all
Upgrade
Version history
3.3.9latest on PyPI · released Mar 12, 2020
Audit
Dependencies
requestsrequiredUsed for HTTP communication with the Tower/AWX API.
Agent activity
32 hits · last 30 days
node
28
OpenAI (training)
1
Resources
ansible-tower-cli — pip install ansible-tower-cli · libregistry