Feedback

Chat Icon

AWX in Action

Ansible Orchestration at Scale

Skip the UI: Driving AWX Entirely From the Command Line
72%

Three Ways to Authenticate

After installing the AWX CLI, you need to configure it to connect to your AWX instance. There are different ways to authenticate with the AWX API.

Authenticating From the CLI

Start by exporting the following environment variables:

# Export these environment variables
export TOWER_HOST=
export TOWER_USERNAME=
export TOWER_PASSWORD=

Example:

export TOWER_HOST=https://awx.example.com
export TOWER_USERNAME=admin
export TOWER_PASSWORD=Ansible123!

Then, generate a token using the following command:

# Generate a token
awx login -k \
    --conf.host $TOWER_HOST \
    --conf.username $TOWER_USERNAME \
    --conf.password $TOWER_PASSWORD

The -k flag ignores SSL certificate verification. The -f human flag formats the output in a human-readable format instead of JSON. You can remove it if you want to see the JSON output.

If you get a ModuleNotFoundError: No module named 'pkg_resources' error, you can install it using the following command:

pip3 install pkg_resources

# or pip install --upgrade "setuptools<81"
# then upgrade
pip install --upgrade awxkit

# Optional: silence the warning
# export PYTHONWARNINGS="ignore::UserWarning:awxkit.cli.client"

You should see a token generated in the output. This is called a "Personal Access Token" and is used to authenticate with the AWX API. This is an example:

{
     "token": "8hds7eFzHRvWC1U8RPze8pLeyMAmED"
}

You should export it as an environment variable:

export TOWER_OAUTH_TOKEN=

Then you can execute commands like this:

awx -k user list -f human
awx -k organization list -f human
awx -k job list -f human

The generated token provides "write" access by default. If you wish to generate a token with "read" access, you can use the --conf.scope flag.

You can enter awx config to view the current configuration.

Authenticating With a curl Call

You can also authenticate with the AWX CLI using the API. Here's how to do it:

First, begin by exporting the following environment variables (already done):

export TOWER_HOST=
export TOWER_USERNAME=
export TOWER_PASSWORD=

Next, generate a token using the command below:

curl -k -X POST -u $TOWER_USERNAME:$TOWER_PASSWORD \
    "$TOWER_HOST/api/v2/tokens/"

You should see a JSON response containing the token. For example:

{
  "id": 10

AWX in Action

Ansible Orchestration at Scale

Enroll now to unlock all content and receive all future updates for free.