Example Bash Aliases File

An example .bash_aliases file with convenient aliases and functions for Ansible development in the PHX environment, including environment setup, Git configuration, and Ansible Vault handling.

 plays/dev/files/.bash_aliases

# This example ".bash_aliases" file provides a set of aliases and functions to
# streamline workflows in an Ansible development environment. It sets environment
# variables for tools like Ansible and Git, defines shortcuts for common commands,
# and includes functions for securely managing Ansible Vault passwords. These
# utilities help with tasks such as activating virtual environments, installing
# Ansible roles and collections, and handling Vault-encrypted files, promoting
# efficiency and best practices in development.
#
# For more information:
# https://c2platform.org/docs/howto/phx/desktop/setup-environment
export ANSIBLE_INVENTORY="Vagrantfile.yml,hosts.ini,hosts-kerberos-override.ini"
export EDITOR=nano
export GIT_USER='tclifton'
export GIT_MAIL='tony.clifton@dev.c2platform.org'
alias python='python3'
alias pip='pip3'
alias phx-env='source ~/.virtualenv/pxd/bin/activate'
alias phx-home='cd ~/git/gitlab/c2/ansible-phx'
alias phx='phx-home && phx-env'
alias phx-roles='phx && ansible-galaxy install -r roles/requirements.yml --force --no-deps -p roles/external'
alias phx-collections='phx && ansible-galaxy collection install -r collections/requirements.yml -p .'
alias phx-vault='ansible-vault edit secret_vars/development/main.yml'
# Function to securely set the Ansible Vault password using environment variable PX_ANSIBLE_VAULT_PASSWORD.
# The password will remain set for the duration of the shell session.
function phx-vault-password-env() {
    local password
    echo -n "Enter Ansible Vault passphrase: " >&2
    read -s password
    echo >&2  # Add a newline after the hidden input
    export PX_ANSIBLE_VAULT_PASSWORD="$password"
    echo "PX_ANSIBLE_VAULT_PASSWORD has been set for this shell session." >&2
    export ANSIBLE_VAULT_PASSWORD_FILE=/usr/local/bin/vault-client.sh
}
# Function to securely set the Ansible Vault password using GNOME Keyring.
# The password will remain for the user session
function phx-vault-password() {
    local pw=$(secret-tool lookup ansible vault 2>/dev/null)
    if [ -z "${pw}" ]; then
        echo "Password doesn't exist or is empty, lets add/set it!"
        pw=$(secret-tool store --label 'Ansible Vault Password' ansible vault >&2)
        echo "Vault password has been set." >&2
    else
        echo "Vault password is already set."
    fi
    export ANSIBLE_VAULT_PASSWORD_FILE=/usr/local/bin/vault-client-keyring.sh
}
export C2_HTTPS_SSH=https  # Use HTTPS for SSH operations
history -s ansible -i hosts.ini -m win_ping pxd-ad
history -s ansible -i hosts.ini -m ping pxd-rproxy1