Last active
May 11, 2022 19:49
-
-
Save SolomonHD/6d8810125a4714cd895fb0b42363116a to your computer and use it in GitHub Desktop.
AWX login script, requires TOWER_USERNAME and TOWER_HOST to be set, uses encpass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Written by Solomon G Hilliard | |
### Additional Functionality ### | |
# To avoid having to set awx token for each shell, create and load this alias: | |
# alias awx='awx --conf.token $(cat ~/.ansible/.awxcli/token)' | |
### Requirements ### | |
# Encpass script: https://github.com/plyint/encpass.sh | |
# AWX CLI: https://github.com/ansible/awx/blob/devel/INSTALL.md#installing-the-awx-cli | |
# TOWER_HOST, TOWER_USERNAME environment variables, CONTROLLER_OAUTH_TOKEN or TOWER_OAUTH_TOKEN depending on your version of awx cli | |
### Troubleshooting ### | |
# If tower password changes, delete ~/.encpass/secrets/awx_get_token.sh/tower_password.enc | |
# Script will then prompt for password again | |
# If SSL errors in Ubuntu, run: | |
# pip3 install --ignore-installed pyOpenSSL --upgrade | |
. encpass.sh | |
tower_password=$(get_secret tower_password) | |
eval $(TOWER_PASSWORD=$tower_password awx login -f human) | |
echo export CONTROLLER_OAUTH_TOKEN=$CONTROLLER_OAUTH_TOKEN | |
if [ ! -d "~/.ansible/.awxcli" ] | |
then | |
mkdir -p ~/.ansible/.awxcli | |
fi | |
### Cache AWX token in home directory | |
echo $CONTROLLER_OAUTH_TOKEN > ~/.ansible/.awxcli/token |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment