From 7b153aab6d0202ddd720f75f9b9ef47b4f386628 Mon Sep 17 00:00:00 2001 From: ogrechko Date: Sun, 28 Dec 2025 21:05:49 +0000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20ansible/deploy=5Fawx=5Fk8s.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ansible/deploy_awx_k8s.yml | 89 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 ansible/deploy_awx_k8s.yml diff --git a/ansible/deploy_awx_k8s.yml b/ansible/deploy_awx_k8s.yml new file mode 100644 index 0000000..67a9950 --- /dev/null +++ b/ansible/deploy_awx_k8s.yml @@ -0,0 +1,89 @@ +--- +- name: Deploy latest AWX on Kubernetes using AWX Operator + hosts: localhost + connection: local + become: false + gather_facts: false + + vars: + awx_namespace: awx + awx_operator_version: 2.19.1 # Latest as of available releases; corresponds to AWX 24.6.1 + awx_instance_name: awx-demo + awx_service_type: nodeport # Change to 'clusterip' if using ingress or on OpenShift + + collections: + - kubernetes.core + + tasks: + - name: Ensure kubernetes.core collection is installed + command: ansible-galaxy collection install kubernetes.core + changed_when: false + ignore_errors: true # In case already installed + + - name: Create AWX namespace + k8s: + state: present + definition: + apiVersion: v1 + kind: Namespace + metadata: + name: "{{ awx_namespace }}" + + - name: Set current namespace context (optional, for convenience) + command: kubectl config set-context --current --namespace={{ awx_namespace }} + changed_when: false + + - name: Install AWX Operator using kustomize + command: >- + kubectl apply -k "github.com/ansible/awx-operator/config/default?ref={{ awx_operator_version }}" + changed_when: false + + - name: Wait for AWX Operator to be ready + k8s_info: + api_version: apps/v1 + kind: Deployment + namespace: "{{ awx_namespace }}" + name: awx-operator-controller-manager + register: operator_deployment + until: operator_deployment.resources[0].status.readyReplicas == operator_deployment.resources[0].status.replicas + retries: 30 + delay: 10 + + - name: Create AWX instance + k8s: + state: present + namespace: "{{ awx_namespace }}" + definition: + apiVersion: awx.ansible.com/v1beta1 + kind: AWX + metadata: + name: "{{ awx_instance_name }}" + spec: + service_type: "{{ awx_service_type }}" + + - name: Wait for AWX pods to be ready + k8s_info: + kind: Pod + namespace: "{{ awx_namespace }}" + label_selectors: + - "app.kubernetes.io/managed-by=awx-operator" + register: awx_pods + until: >- + awx_pods.resources | selectattr('status.phase', 'equalto', 'Running') | length == awx_pods.resources | length + retries: 60 + delay: 10 + + - name: Get AWX admin password + k8s_info: + api_version: v1 + kind: Secret + namespace: "{{ awx_namespace }}" + name: "{{ awx_instance_name }}-admin-password" + register: awx_secret + + - name: Display AWX access information + debug: + msg: >- + AWX is deployed. Access it at the NodePort service (use 'kubectl get svc {{ awx_instance_name }}-service -n {{ awx_namespace }}' to find the port). + Default username: admin + Password: {{ awx_secret.resources[0].data.password | b64decode }} \ No newline at end of file