In this post I’m going to cover how I setup AWX in AWS.  Now I know Amazon has a GitHub with instructions and for the most part they work.  However, AWX has had some changes since this was posted and it requires the templates to be updated a bit.

First things first.  I downloaded the original GitHub repo from Amazon.  The original repo can be found below if you want to check it for reference.  I will have the updated version on my GitHub with the required updates for it to work if you just want to clone mine.

Original:

aws-quickstart/quickstart-awx
AWS Quick Start Team. Contribute to aws-quickstart/quickstart-awx development by creating an account on GitHub.

Mine:

glitchv0/AWX-on-AWS
An updated version of Amazon’s outdated repo. Contribute to glitchv0/AWX-on-AWS development by creating an account on GitHub.

The first thing that is missing is the VPC submodule.  This comes from the AWS quick start repo but for some reason isn’t included in the AWX one.  So, first things first I added that file to the following folder.  For reference the original repo for the VPC template is below.

 \submodules\quickstart-aws-vpc\templates
aws-quickstart/quickstart-aws-vpc
AWS Quick Start Team. Contribute to aws-quickstart/quickstart-aws-vpc development by creating an account on GitHub.

The next thing we need to do is update the AWX version that we want to use.  At the time of this writing AWX 9.2.0.  There are 3 files that reference the AWX version and we need to add this new version to them.  The files are:

\templates\awx.template
\templates\awx-workload.template
\templates\awx-master-template

We want to update the section labeled AWXVersion in each of these files.  By default, they are set to version 6.1.0 which is rather old in terms of what version of ansible and AWX features.  We are going to add version 9.2.0 as the default and allowed version.

Line 44 in awx.template I changed
Default: 6.1.0
To 
Default: 9.2.0
After line 49 I added
- 9.2.0
awx.template
Line 119 in awx-workload.template I changed
Default: 6.1.0
To 
Default: 9.2.0
After line 124 I added
- 9.2.0
awx-workload.template
Line 95 in awx-master.template I changed
Default: 6.1.0
To 
Default: 9.2.0
After line 100 I added
- 9.2.0
awx-master.template

Now we have the most current version of AWX and this comes with Ansible 2.9.3 (at the time of this writing 2.9.5 is the most current).  The next thing that I need to update was the CodeBuild section to follow the new locations AWX puts its files.  I also updated the CodeBuild image to Amazon’s standard, so it doesn’t have to pull from docker hub.

Line 150 in awx.template I changed
Image: docker.io/amazonlinux:2017.09
To
Image: aws/codebuild/standard:3.0
awx.template

The next thing I had to update was the actual CodeBuild script that builds the images before pushing them to EKR.  They have old file locations and wouldn’t work with newer versions of AWX.

Line 193 in awx.template I changed
install:
commands:
To
install:
Runtime-versions:
docker: 18
commands:
awx.template
Line 197 through 200 I changed
- yum install -y git gcc docker python27-pip python27-devel libffi-devel openssl-devel curl util-linux
- /usr/bin/pip install -U docker docker-compose ansible awscli
- service docker start
To
- apt-get -y update
- apt-get -y install build-essential libssl-dev libffi-dev python-dev python3-dev python3-venv git
- /usr/local/bin/pip3  install -U docker docker-compose ansible awscli
awx.template

The observant among you will notice that we are now doing apt-get instead of yum.  That is because the standard image is Ubuntu based instead of CentOS based.

Now comes the changes that took some time to figure out.  AWX changed it’s location for files from /tmp/awxcompose to ~./.awx/awxcompose.  I had to update the following lines to account for that and the fact that we now needed to grab nginx.conf as well.

Lines 221 through 230 I changed
- cp -drpu /tmp/awxcompose/ sidecar/tmp/
- echo "changes"
- echo "FROM ansible/awx_web:${AWX_VERSION}" > sidecar/Dockerfile
- echo "VOLUME /etc/tower/" >> sidecar/Dockerfile
- echo "COPY --chown=1000 /tmp/awxcompose/credentials.py /etc/tower/conf.d/credentials.py" >> sidecar/Dockerfile
- echo "COPY --chown=1000 /tmp/awxcompose/SECRET_KEY /etc/tower/SECRET_KEY" >> sidecar/Dockerfile
- echo "COPY --chown=1000 /tmp/awxcompose/environment.sh /etc/tower/conf.d/environment.sh" >> sidecar/Dockerfile
To
- cp -drpu ~/.awx/awxcompose sidecar/tmp/
- echo "changes"
- echo "FROM ansible/awx_web:${AWX_VERSION}" > sidecar/Dockerfile
- echo "VOLUME /etc/tower/" >> sidecar/Dockerfile
- echo "VOLUME /etc/nginx/" >> sidecar/Dockerfile
- echo "COPY --chown=1000 tmp/awxcompose/credentials.py /etc/tower/conf.d/credentials.py" >> sidecar/Dockerfile
- echo "COPY --chown=1000 tmp/awxcompose/SECRET_KEY /etc/tower/SECRET_KEY" >> sidecar/Dockerfile
- echo "COPY --chown=1000 tmp/awxcompose/environment.sh /etc/tower/conf.d/environment.sh" >> sidecar/Dockerfile
- echo "COPY --chown=1000 tmp/awxcompose/nginx.conf /etc/nginx/nginx.conf" >> sidecar/Dockerfile

With that I have done all the needed updates to actually run this in AWS.  In part 2 of this, I will take you through how to actually use this to deploy AWX into AWS.

AWX on AWS - Part 2
Cloud/Automation/Linux