DevOps | Scripts | Automation

AnsibleAWX

Installing Ansible AWX on the Ubuntu server

Hello Guys,

In today’s article, we will go through step by step of Ansible AWX (alternative to Ansible Tower) which is the community edition. We will use the MiniKube to create a Kubernetes cluster and install AWX on it.

Notes
  • For this article, we have used Ubuntu 22.04 WSL version with a basic system configuration (4GB RAM and 8 cores). For the dev and test environment this configuration is OK for testing but for production choose wisely as per your load analysis.
  • You can choose other Linux distributions as VM and commands may vary. Apply commands accordingly.
  • We are installing the AWX 21.0 version using the Awx-Operator method, after version 18.0, Awx-Operator is the preferred method to install Awx. You can confirm it on the AWX GitHub page.
https://github.com/ansible/awx/blob/devel/INSTALL.md
  • Before starting the installation make sure you have sufficient space in /var and /home drive to avoid getting errors for disk space.
  • In this article, we are using Internal postgres DB for AWX.
Table of Content
  1. Install Minikube.
  2. Install Kustomize tool.
  3. Install dependent Virtualization driver – Docker
  4. Create Minikube cluster.
  5. Deploy Awx-Operator using kustomization.yaml.
  6. Deploy AWX.
  7. Configure port forwarding for AWX console access.
1. Install Minikube

There are multiple ways to create a Kubernetes cluster like kubeadm, minikube, etc. We will use a lightweight minikube for lab purposes.

You can download minikube from the link below.

https://minikube.sigs.k8s.io/docs/start/

We are using the Ubuntu OS, so use the below command for minikube installation on Ubuntu.

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
Check minikube version

Once you have minikube installed, use the minikube version command to check the version of minikube.

2. Install Kustomize

Once minikube is installed, install the kustomize tool to apply configuration for Kubernetes.

Check the below URL for the kustomize tool download link.

https://kubectl.docs.kubernetes.io/installation/kustomize/

Here, we are using the binary installation method but you can choose as per your convenience.

curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"  | bash

Once you have the kustomize tool installed, type kustomize to confirm the installation.

Kustomize tool

If the kustomize command doesn’t recognize, type the below command to move the kustomize tool to the bin directory. It should work. !!

sudo mv /home/$USER/kustomize /usr/bin/
3. Install Docker

To start the minikube cluster there are a few dependencies and docker is one of them. You can download and install docker as per your environment operating system from the below link.

https://docs.docker.com/engine/install/

4. Create MiniKube cluster

Alright, pre-requisites should be complete by now. If any of the above components mare issing, make sure you go back and install it again otherwise MiniKube cluster won’t start.

To create/start the minikube cluster, run the below command.

minikube start --cpus=4 --memory=6g --addons=ingress

You need at least 2GB of memory and 2 CPU to start the cluster. You can customize the memory and CPU as per your cluster load. Even once the system is restarted or if you stop minikube intentionally, you can always start minikube with the custom configuration.

Check below the official minimum requirement to start the cluster.

https://minikube.sigs.k8s.io/docs/start/

Once the cluster is started, the above command output should be as below.

minikube start

Once, the cluster starts, check if the minikube is ready.

minikube kubectl -- get nodes
minikube Control-Plane status.

The above output shows that the control-plane is in the ready state. Control Planes manage the cluster and the nodes used to host the running applications. Learn more about the control plane and nodes on the minikube cluster.

https://kubernetes.io/docs/tutorials/kubernetes-basics/create-cluster/cluster-intro/

To get all running pods from all namespaces,

minikube kubectl -- get pods -A

To learn more about pods, check below K8 link.

https://kubernetes.io/docs/concepts/workloads/pods/

The output of the above command is shown below.

kubectl get pods

Now, set the alias so you don’t need to use minikube before the kubectl command every time which means you can directly run the kubectl — get pods -A command without adding minikube.

alias kubectl="minikube kubectl --"

The above command sets alias temporary. Once you restart VM, it vanishes. To set the alias permanently set the bashrc file in the Linux system.

5. Deploy Awx-Operator using kustomization.yaml file
  • Once your cluster is up and running, you need to apply AWX-Operator configuration on the server. The configuration is stored in kustomization.yaml file. You can download the sample Kustomization.yaml file from the Github repo and copy or create it on the VM.

https://github.com/chiragce17/MyPublicRepo/blob/main/AWX/kustomization.yaml

  • Edit the file before you apply the configuration. You need to provide the latest release tag in the file and the same can be found from the lo

https://github.com/ansible/awx-operator/releases

Awx-Operator latest release tag
  • Apply the configuration using the below command.
kustomize build . | kubectl apply -f -
Output of Kustomization.yaml applied configuration
  • Wait for a few mins, the awx-operator pod should be up and running.
kubectl get pods -n awx
kubectl get podsoutput
  • If you don’t want to apply namespace (-n awx) every time in commands, you can change the default namespace to awx using the below command.
kubectl config set-context --current --namespace=awx
  • Now, create a file name: awx-demo.yaml (you can choose your own) and copy the content from the git repo below.

https://github.com/chiragce17/MyPublicRepo/blob/main/AWX/awx-demo.yaml

  • Modify the kustomization.yaml to add the awx-demo.yaml file. kustomization.yaml file should look like the below.
Modified kustomization.yaml
  • Run the Kustomize command to apply the latest configuration.
kustomize build . | kubectl apply -f -
Output of Kustomize applied configuration

Once the configuration is applied, after a few mins you can see the AWX pods are up and running. Use the below commands to check the status.

kubectl get pods -l "app.kubernetes.io/managed-by=awx-operator" -n awx
Pod Status
kubectl get svc -l "app.kubernetes.io/managed-by=awx-operator" -n awx
Pod Status

You can also run the below commands to get the entire deployment status in awx namespace.

kubectl get all -n awx
Get all pods in the AWX namespace

Awx is deployed now using the minikube. Please note that we have used here internal Postgres DB.

To get the AWX console URL run the below command.

minikube service awx-demo-service --url -n awx
Awx console output

For the demo purpose, we have used WSL (Windows Subsystem for Linux) Ubuntu VM so we are getting http://127.0.0.1:46539 URL. You can hit this URL to open AWX console page.

AWX Console page.

It many happen that URL won’t work because of the port redirection issue. There can be many reasons for the port redirection issue. Some of them are listed below.

  • Your application is inside the minikube environment not directly on the VM, you may need to expose the port of the service to external IP. See the guide here: https://minikube.sigs.k8s.io/docs/handbook/accessing/
  • Disable or allow specific NodePort traffic on the VM.
  • Check your VM port is open. If your VM is hosted on cloud provider then you may need to open or create a rule to allow traffic on the NodePort.
  • run curl -l <URL> to check if you are getting HTML webpage on the screen.