#!/bin/bash
# --- Configuration ---
AWX_OPERATOR_VERSION="2.19.1"
NAMESPACE="awx"
KUBECONFIG_PATH="/etc/rancher/k3s/k3s.yaml"
echo "๐งน Phase 1: Cleaning up existing K3s for a fresh start..."
[ -f /usr/local/bin/k3s-uninstall.sh ] && /usr/local/bin/k3s-uninstall.sh
# Remove old manifests to avoid conflicts
rm -f kustomization.yaml awx-instance.yaml
echo "๐ฆ Phase 2: Installing fresh K3s..."
curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644
export KUBECONFIG=$KUBECONFIG_PATH
echo "⏳ Waiting for K3s node to reach 'Ready' state..."
sleep 20
kubectl wait --for=condition=Ready node/$(hostname) --timeout=90s
# Create Namespace
kubectl create namespace $NAMESPACE --dry-run=client -o yaml | kubectl apply -f -
echo "๐️ Phase 3: Deploying AWX Operator via Kustomize (with Image Fixes)..."
# This Kustomization solves the 404 URL error AND the gcr.io ImagePullBackOff error
cat <<EOF > kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- github.com/ansible/awx-operator/config/default?ref=$AWX_OPERATOR_VERSION
images:
- name: quay.io/ansible/awx-operator
newTag: $AWX_OPERATOR_VERSION
- name: gcr.io/kubebuilder/kube-rbac-proxy
newName: quay.io/brancz/kube-rbac-proxy
newTag: v0.15.0
namespace: $NAMESPACE
EOF
# Apply the operator
kubectl apply -k .
echo "๐ Phase 4: Creating AWX Instance manifest..."
cat <<EOF > awx-instance.yaml
apiVersion: awx.ansible.com/v1beta1
kind: AWX
metadata:
name: awx-demo
namespace: $NAMESPACE
spec:
service_type: nodeport
postgres_storage_class: local-path
EOF
# Ensure CRDs are registered before applying the instance
echo "๐ฐ️ Waiting for CRDs to settle, then deploying AWX Instance..."
sleep 20
kubectl apply -f awx-instance.yaml
echo "----------------------------------------------------------"
echo "๐ AWX DEPLOYMENT INITIALIZED"
echo "----------------------------------------------------------"
# Final Phase: Credential Discovery
echo "๐ Waiting for AWX to generate the admin password..."
until kubectl get secret awx-demo-admin-password -n $NAMESPACE &> /dev/null; do
echo -n "."
sleep 10
done
# Grab details automatically
ADMIN_PASS=$(kubectl get secret awx-demo-admin-password -n $NAMESPACE -o jsonpath='{.data.password}' | base64 --decode)
NODE_PORT=$(kubectl get svc awx-demo-service -n $NAMESPACE -o jsonpath='{.spec.ports[0].nodePort}')
SERVER_IP=$(hostname -I | awk '{print $1}')
echo -e "\n\n✅ INSTALL COMPLETE!"
echo "----------------------------------------------------------"
echo "ACCESS URL: http://$SERVER_IP:$NODE_PORT"
echo "USERNAME: admin"
echo "PASSWORD: $ADMIN_PASS"
echo "----------------------------------------------------------"
echo "๐ Watch progress: kubectl get pods -n $NAMESPACE -w"
-------------------------------------------------------------------------------------------------------------------
enter the below for the password
kubectl get secret awx-demo-admin-password -n awx -o jsonpath='{.data.password}' | base64 --decode; echo
# Find the NodePort (it will be the 5-digit number after the '80:')
kubectl get svc awx-demo-service -n awx
# Find your Public/Private IP
hostname -I | awk '{print $1}'