Преглед на файлове

Merge pull request #732 from Lakshmi-Patneedi/devel

Issue #731: Adding Pre-requisites for AWX
John Lockman преди 3 години
родител
ревизия
834594a4c3

+ 117 - 0
control_plane/roles/webui_awx/tasks/check_prerequisites.yml

@@ -0,0 +1,117 @@
+# Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+---
+
+- name: Initialize variables
+  set_fact:
+    awx_pod_deployment_status: false
+    awx_ui_status: false
+    awx_configuration_status: false
+
+- name: Fetching pods from AWX namespace
+  command: "kubectl get pods -n {{ awx_namespace }}"
+  register: awx_pods
+  changed_when: false
+
+- name: Fetching deployment from AWX namespace
+  command: "kubectl get deployment -n {{ awx_namespace }}"
+  register: awx_deployment
+  changed_when: false
+
+- name: Updating awx_pod_deployment_status
+  set_fact:
+    awx_pod_deployment_status: true
+  when:
+    - awx_deployment.stdout | regex_search('awx')
+    - awx_pods.stdout | regex_search('awx-([A-Za-z0-9]{10})-([A-Za-z0-9]{5})')
+  failed_when: false
+
+- name: Check if config file exists
+  stat:
+    path: "{{ tower_config_file }}"
+  register: tower_config_file_status
+
+- name: Check if tower_vault_key exists
+  stat:
+    path: "{{ tower_vault_file }}"
+  register: tower_vault_file_status
+
+- name: Fetching services of awx
+  command: kubectl get svc -n {{ awx_namespace }}
+  register: awx_services_list
+  changed_when: false
+
+- block:
+    - name: Get awx-service cluster-ip
+      command: "kubectl get svc {{ awx_service_name }} -n {{ awx_namespace }} -o jsonpath='{.spec.clusterIP}'"
+      register: awx_cluster_ip
+
+    - name: Get AWX admin password
+      shell: >
+        set -o pipefail && \
+        kubectl get secret awx-admin-password -n {{ awx_namespace }} -o jsonpath='{.data.password}' | base64 --decode
+      no_log: true
+      register: awx_admin_password
+
+    - name: Waiting for the AWX UI to be up
+      uri:
+        url: "http://{{ awx_cluster_ip.stdout }}:{{ awx_port }}"
+        status_code: "{{ return_status }}"
+      register: display
+      until: display.status == return_status
+      retries: "{{ min_retries }}"
+      delay: "{{ max_delay }}"
+      failed_when: false
+
+    - name: Waiting for the AWX UI to be up and running
+      uri:
+       url: "http://{{ awx_cluster_ip.stdout }}:{{ awx_port }}"
+       status_code: "{{ return_status }}"
+       return_content: true
+      register: web_ui
+      until: awx_ui_msg not in web_ui.content
+      retries: "{{ min_retries }}"
+      delay: "{{ max_delay }}"
+      failed_when: false
+
+    - name: Updating awx_ui_status
+      set_fact:
+        awx_ui_status: true
+      when: awx_ui_msg not in web_ui.content
+
+    - block:
+         - name: Fetching Schedule from AWX UI
+           command: awx schedules list --all --conf.host http://{{ awx_cluster_ip.stdout }}:{{ awx_port }} --conf.username admin --conf.password {{ awx_admin_password.stdout }} -f human --filter "name"
+           register: awx_schedule_list
+
+         - name: Fetching job_templates from AWX UI
+           command: awx job_templates list --all --conf.host http://{{ awx_cluster_ip.stdout }}:{{ awx_port }} --conf.username admin --conf.password {{ awx_admin_password.stdout }} -f human --filter "name"
+           register: awx_job_templates_list
+
+         - name: Updating awx_configuration_status
+           set_fact:
+             awx_configuration_status: true
+           when:
+             - ' scheduled_templates[1].name in awx_schedule_list.stdout'
+             - ' scheduled_templates[0].name in awx_schedule_list.stdout'
+             - ' omnia_job_template_details[0].name in awx_job_templates_list.stdout'
+             - ' job_template_details[5].name in awx_job_templates_list.stdout'
+             - ' job_template_details[0].name in awx_job_templates_list.stdout'
+             - ' job_template_details[4].name in awx_job_templates_list.stdout'
+      when: awx_ui_status == true
+      ignore_errors: true
+  when:
+    - tower_config_file_status.stat.exists
+    - tower_vault_file_status.stat.exists
+    - awx_services_list.stdout | regex_search('awx-ui')

+ 10 - 11
control_plane/roles/webui_awx/tasks/main.yml

@@ -1,4 +1,4 @@
-# Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+# Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -19,22 +19,21 @@
   include_tasks: ../../control_plane_common/tasks/internet_validation.yml
   tags: install
 
-- name: Install AWX
-  include_tasks: install_awx.yml
+- name: Check awx prequisites
+  include_tasks: check_prerequisites.yml
   tags: install
 
-- name: Internet validation
-  include_tasks: ../../control_plane_common/tasks/internet_validation.yml
+- name: Install AWX
+  include_tasks: install_awx.yml
+  when: not awx_pod_deployment_status
   tags: install
 
 - name: Configure settings
   include_tasks: configure_settings.yml
+  when: not awx_ui_status
   tags: install
-
-- name: Internet validation
-  include_tasks: ../../control_plane_common/tasks/internet_validation.yml
-  tags: install
-
+  
 - name: Configure AWX
   include_tasks: awx_configuration.yml
-  tags: install
+  when: not awx_configuration_status
+  tags: install

+ 4 - 1
control_plane/roles/webui_awx/vars/main.yml

@@ -1,4 +1,4 @@
-# Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+# Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -46,6 +46,9 @@ return_status: 200
 max_retries: 20
 max_delay: 15
 
+# Usage: check_prerequisites_awx.yml
+min_retries: 2
+
 # Usage: awx_configuration.yml
 default_org: Default
 default_template: 'Demo Job Template'