Site icon techbeatly

Install Ansible AWX on Kubernetes

Ansible AWX is one of the upstream project for Red Hat Ansible Tower. AWX provides a web-based user interface, REST API, and task engine built on top of Ansible.

Installation of Ansible AWX is simple and pretty straightforward with latest version. (If you are trying to install older than version 18, then you need to follow the docker based method.) AWX will be installed using AWX Operator on top of Kubernetes or OpenShift cluster.

Setup a Kubernetes Cluster

You can use any existing or new cluster or even spin up a minikube cluster on your laptop/workstation for testing purpose.

Read : How to Install a minikube on GCP or Install minikube using Vagrant and VirtualBox

Please note down the memory and cpu requirements as Ansible AWX pods need some minimum resource to run.

$ minikube start --addons=ingress --cni=flannel --install-addons=true \
    --kubernetes-version=stable \
    --vm-driver=docker --wait=false \
    --cpus=4 --memory=6g

Enable Addons as needed

## Check addons
$ minikube addons list
$ minikube addons enable metrics-server
$ minikube dashboard

Deploy AWX Operator

Access your cluster and deploy AWX operator; replace TAG with the version from Release Page

$ kubectl apply -f https://raw.githubusercontent.com/ansible/awx-operator/<TAG>/deploy/awx-operator.yaml

Create AWX Deployment

Create a file awx-demo.yaml with below content.

---
apiVersion: awx.ansible.com/v1beta1
kind: AWX
metadata:
  name: awx-demo
spec:
  service_type: nodeport
  ingress_type: none
  hostname: awx-demo.example.com

Create the resource.

$ kubectl apply -f awx-demo.yml
awx.awx.ansible.com/awx-demo created

Refer AWX Operator documentation for advanced installation options.

Get the Admin Password for Ansible AWX

By default, the admin user is admin and the password is available in the <resourcename>-admin-password secret.

$ kubectl get secret awx-demo-admin-password \
  -o jsonpath="{.data.password}" | base64 --decode
lxQ8uWlE9Wevkgmy5Kx2AqFdY80v34gx

Get the Path to Access Ansible AWX

You will find the NodePort and IP for service awx-demo-service

$ kubectl get svc
NAME                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)             AGE
awx-demo-postgres      ClusterIP   None             <none>        5432/TCP            23m
awx-demo-service       NodePort    10.110.146.161   <none>        80:31726/TCP        23m
awx-operator-metrics   ClusterIP   10.104.113.88    <none>        8383/TCP,8686/TCP   23m
kubernetes             ClusterIP   10.96.0.1        <none>        443/TCP             26m

Now you can access the Ansible AWX Portal at IP_ADDRESS:NODE_PORT.

Access Ansible AWX on Remote Minikube or Kubernetes Cluster

If your Kubernetes/minikube Cluster is on Remote Machine/VM (eg: Cloud Instance with Public IP) then you can access it using above method (if NodePort is same is remote IP) or you can use LoadBalancer methods.

In our case, we have deployed this in a Google Cloud instance without GUI and we need to enabled port-forwarding as below.

$ minikube ser## Forward localhost (minkube VM Localhost) port 7080 -> 80
$ kubectl port-forward service/awx-demo-service 7080:80

So the Ansible AWX service is available at minikube VM localhost:7080 now; but we dont have GUI there to access !!

So, we do a port-forwarding from our laptop/workstation via SSH Tunnel.

## On your Workstation/Laptop
## eg: ssh -L LOCAL_PORT:localhost:REMOTE_PORT User@REMOTE_IP
$ ssh -L 7080:localhost:7080 gini@123.123.234.234

Now, open a browser on your laptop/workstation and goto localhost:7080; that’s it.

Enjoy Ansible AWX running on top of Kubernetes or minikube.

Exit mobile version