Ansible Tower/AWX Operator
An Ansible Tower operator for Kubernetes built with Operator SDK and Ansible.
Also configurable to run the open source AWX instead of Tower (helpful for certain use cases where a license requirement is not warranted, like CI environments).
Purpose
There are already OpenShift/Kubernetes installers available for both AWX and Ansible Tower:
This operator is meant to provide a more Kubernetes-native installation method for Ansible Tower or AWX via a Tower Custom Resource Definition (CRD).
So instead of having to maintain a separate playbook, inventory, and installation configuration for each Tower instance, you can deploy the following Custom Resource (CR) to an existing Kubernetes or OpenShift cluster:
apiVersion: tower.ansible.com/v1alpha1
kind: Tower
metadata:
name: tower
namespace: ansible-tower
spec:
tower_hostname: tower.mycompany.com
tower_secret_key: aabbcc
tower_admin_user: test
tower_admin_email: test@example.com
tower_admin_password: changeme
After a few minutes, your new Tower instance will be accessible at http://tower.mycompany.com/ (assuming your cluster has an Ingress controller configured).
Usage
TODO: See Issue #4.
Development
Testing
This Operator includes a Molecule-based test environment, which can be executed standalone in Docker (e.g. in CI or in a single Docker container anywhere), or inside any kind of Kubernetes cluster (e.g. Minikube).
You need to make sure you have Molecule installed before running the following commands. You can install Molecule with:
pip install 'molecule[docker]
Running molecule test sets up a clean environment, builds the operator, runs all configured tests on an example operator instance, then tears down the environment (at least in the case of Docker).
If you want to actively develop the operator, use molecule converge, which does everything but tear down the environment at the end.
Testing in Docker (standalone)
molecule test -s test-local
This environment is meant for headless testing (e.g. in a CI environment, or when making smaller changes which don't need to be verified through a web interface). It is difficult to test things like Tower's web UI or to connect other applications on your local machine to the services running inside the cluster, since it is inside a Docker container with no static IP address.
Testing in Minikube
minikube start --memory 6g --cpus 2
minikube addons enable ingress
molecule test -s test-minikube
Minikube is a more full-featured test environment running inside a full VM on your computer, with an assigned IP address. This makes it easier to test things like NodePort services and Ingress from outside the Kubernetes cluster (e.g. in a browser on your computer).
Once the operator is deployed, you can visit the Tower UI in your browser by following these steps:
- Make sure you have an entry like
IP_ADDRESS example-tower.testin your/etc/hostsfile. (Get the IP address withminikube ip.) - Visit
http://example-tower.test/in your browser.
Release Process
There are a few moving parts to this project:
- The Docker image which powers Tower Operator.
- The
tower-operator.yamlKubernetes manifest file which initially deploys the Operator into a cluster.
Each of these must be appropriately built in preparation for a new tag:
Build a new release of the Operator for Docker Hub
Run the following command inside this directory:
operator-sdk build geerlingguy/tower-operator:0.1.0
Then push the generated image to Docker Hub:
docker login -u geerlingguy
docker push geerlingguy/tower-operator:0.1.0
Build a new version of the tower-operator.yaml file
Update the tower-operator version in two places:
deploy/tower-operator.yaml: in theansibleandoperatorcontainer definitions in thetower-operatorDeployment.build/chain-operator-files.yml: theoperator_imagevariable.
Once the versions are updated, run the playbook in the build/ directory:
ansible-playbook chain-operator-files.yml
After it is built, test it on a local cluster:
minikube start
kubectl apply -f deploy/tower-operator.yaml
kubectl apply -f deploy/crds/tower_v1alpha1_tower_cr_awx.yaml
<test everything>
minikube delete
If everything works, commit the updated version, then tag a new repository release with the same tag as the Docker image pushed earlier.