Welcome! I use these scripts to automate the provisioning of an AWX (Ansible Tower) demo environment. It does the following:
- Install all dependencies of Ansible, AWX and Docker.
- Prepares the AWX install environment.
- Installs AWX using the prepared environment.
- Combines Vault-encrypted secrets with a config file to post-configure AWX.
There is an example cloud-init.sh script in this repo, which can be used in your cloud-init for AWS or Azure. The elements of this script are broken down below into their component parts!
apt-get update
apt-get install -y python3-pip python-pip git
pip3 install ansible ansible-tower-cli # I'm preferring Python 3 for Ansible and Tower-CLI
pip2 install docker docker-compose # Ansible at 2.9 uses Python 2 for Docker/Docker-Compose :(
git clone https://github.com/JonTheNiceGuy/Install_AWX_And_Configure_It.git /tmp/build_playbook
cd /tmp/build_playbook
Note, this should be VAULT encrypted!
See secrets.yml.example for example, plaintext content.
echo "<CONTENT>" > secrets.yml
See run.json.example for example config settings.
echo "<CONTENT>" > run.json
This builds a repeatable script to be able to run the post-install scripts into the AWX environment.
mkdir /root/awx_build
echo "#!/bin/bash" > /root/awx_build/creds
echo "export AWX_Hostname=$(hostname)" >> /root/awx_build/creds
echo "export AWX_Password=\"<AWX_ADMIN_PASSWORD>\"" >> /root/awx_build/creds
echo "echo \"<ANSIBLE_VAULT_PASSWORD>\" > /tmp/build_playbook/vaultfile" >> /root/awx_build/creds
echo "echo \"{
'ansible_fqdn':'$(hostname)',
'admin_password':'<AWX_ADMIN_PASSWORD>'
}\" > /tmp/build_playbook/extra.json" >> /root/awx_build/creds
echo '$*' >> /root/awx_build/creds
chmod +x /root/awx_build/creds
The first script was inspired by https://github.com/geerlingguy/ansible-role-awx and https://github.com/AgentCormac/ProjectX.
This creates some values (notably the password to use for AWX, and the hostname), and clones the AWX repo to a named path. Then it runs the installer from that repo.
/root/awx_build/creds ansible-playbook prepare_awx_install.yml -e "@/tmp/build_playbook/extra.json"
cd /opt/awx/installer
ansible-playbook -i inventory install.yml
This reads the secrets which were populated above and combines it with the post-install config to create a config file, that is then applied against your AWX server.
cd /tmp/build_playbook
/root/awx_build/creds bash ./run.sh