Forráskód Böngészése

Merge pull request #527 from abhishek-s-a/cluster_validation

Issue #521: Cluster validation changes for nfs_node
Lucas A. Wilson 3 éve
szülő
commit
820893909a

+ 91 - 0
roles/cluster_validation/tasks/fetch_powervault_status.yml

@@ -0,0 +1,91 @@
+#  Copyright 2021 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: Check tower_cli.cfg is encrypted
+  command: cat "{{ tower_config_path }}"
+  changed_when: false
+  register: awx_content
+  run_once: true
+  no_log: true
+
+- name: Decrpyt tower_cli.cfg
+  command: ansible-vault decrypt "{{ tower_config_path }}" --vault-password-file "{{ tower_vault_path }}"
+  changed_when: false
+  run_once: true
+  when: "'$ANSIBLE_VAULT;' in awx_content.stdout"
+
+- name: Fetch awx host
+  command: grep "host:" "{{ tower_config_path }}"
+  register: fetch_awx_host
+  changed_when: false
+  run_once: true
+
+- name: Fetch awx username
+  command: grep "username:" "{{ tower_config_path }}"
+  register: fetch_awx_username
+  changed_when: false
+  run_once: true
+  no_log: true
+
+- name: Fetch awx password
+  command: grep "password:" "{{ tower_config_path }}"
+  register: fetch_awx_password
+  changed_when: false
+  run_once: true
+  no_log: true
+
+- name: Set awx variables
+  set_fact:
+    awx_host: "{{ fetch_awx_host.stdout | regex_replace('host: ','') }}"
+    awx_username: "{{ fetch_awx_username.stdout | regex_replace('username: ','') }}"
+    awx_password: "{{ fetch_awx_password.stdout | regex_replace('password: ','') }}"
+  no_log: true
+
+- name: Encrypt tower_cli.cfg
+  command: ansible-vault encrypt "{{ tower_config_path }}" --vault-password-file "{{ tower_vault_path }}"
+  changed_when: false
+  run_once: true
+  when: "'$ANSIBLE_VAULT;' in awx_content.stdout"
+
+- name: Get inventory list
+  command: >-
+    awx --conf.host "{{ awx_host }}" --conf.username "{{ awx_username }}" --conf.password "{{ awx_password }}"
+    inventory list -f human --filter "name"
+  register: inventory_list
+  run_once: true
+  changed_when: false
+  no_log: true
+
+- block:
+    - name: Fetch powervault_me4_inventory
+      command: >-
+        awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
+        hosts list --inventory "{{ powervault_inventory_name }}" -f human --filter "name"
+      register: fetch_inventory
+      run_once: true
+      changed_when: false
+      no_log: true
+
+    - name: Set powervault_status
+      set_fact:
+        powervault_status: true
+      when: fetch_inventory.stdout_lines[2:] | length > 0
+
+    - name: Create powervault_me4 group
+      add_host:
+        name: "{{ item | regex_replace(' ','') }}"
+        groups: "{{ powervault_group }}"
+      when: powervault_status
+      with_items: "{{ fetch_inventory.stdout_lines[2:] }}"

+ 63 - 8
roles/cluster_validation/tasks/main.yml

@@ -1,4 +1,4 @@
-#  Copyright 2020 Dell Inc. or its subsidiaries. All Rights Reserved.
+#  Copyright 2021 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.
@@ -12,6 +12,7 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 ---
+
 - name: Perform validations
   include_tasks: validations.yml
 
@@ -20,18 +21,72 @@
 
 - name: Check if omnia is running from AWX
   block:
-    - name: Appliance status
+    - name: Initialize variables
       set_fact:
-        appliance_status: false
+        control_plane_status: false
+        powervault_status: false
+        nfs_node_status: false
 
     - name: Check AWX instance
-      command: awx-manage --version
+      command: awx --version
+      changed_when: false
+      failed_when: false
+      register: awx_version_check
+
+    - name: Check AWX hostname
+      command: hostname
+      changed_when: false
+      register: awx_hostname
 
-    - name: Update appliance status
+    - name: Set control_plane_status
       set_fact:
-        appliance_status: true
+        control_plane_status: true
+      when:
+        - not awx_version_check.failed
+        - '"awx-" in awx_hostname.stdout'
+
+    - name: Set NFS node status
+      set_fact:
+        nfs_node_status: true
+      when:
+        - control_plane_status
+        - groups['nfs_node'] | length == 1
+
+    - name: Fetch powervault status
+      include_tasks: fetch_powervault_status.yml
+      when: nfs_node_status
 
-  rescue:
+- name: omnia.yml runing on host
+  block:
     - name: Passwordless SSH status
       debug:
-        msg: "omnia.yml running on host"
+        msg: "omnia.yml running on host"
+
+    - name: Check whether ansible config file exists
+      stat:
+        path: "{{ ansible_conf_file_path }}/ansible.cfg"
+      register: ansible_conf_exists
+
+    - name: Create the directory if it does not exist
+      file:
+        path: "{{ ansible_conf_file_path }}"
+        state: directory
+        mode: "{{ file_perm }}"
+      when: not ansible_conf_exists.stat.exists
+
+    - name: Create ansible config file if it does not exist
+      copy:
+        dest: "{{ ansible_conf_file_path }}/ansible.cfg"
+        mode: "{{ file_perm }}"
+        content: |
+          [defaults]
+          log_path = /var/log/omnia.log
+      when: not ansible_conf_exists.stat.exists
+
+    - name: Set omnia.log file
+      replace:
+        path: "{{ ansible_conf_file_path }}/ansible.cfg"
+        regexp: '#log_path = /var/log/ansible.log'
+        replace: 'log_path = /var/log/omnia.log'
+      when: ansible_conf_exists.stat.exists
+  when: not control_plane_status

+ 10 - 2
roles/cluster_validation/tasks/validations.yml

@@ -1,4 +1,4 @@
-#  Copyright 2020 Dell Inc. or its subsidiaries. All Rights Reserved.
+#  Copyright 2021 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.
@@ -12,6 +12,7 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 ---
+
 - name: Validate skip tags
   fail:
     msg: "{{ skip_tag_fail_msg }}"
@@ -27,4 +28,11 @@
   assert:
     that: "groups['compute'] | length | int >= 1"
     fail_msg: "{{ compute_group_fail_msg }}"
-    success_msg: "{{ compute_group_success_msg }}"
+    success_msg: "{{ compute_group_success_msg }}"
+
+- name: NFS group to contain exactly 1 node
+  assert:
+    that: "groups['nfs_node'] | length | int == 1"
+    fail_msg: "{{ nfs_node_group_fail_msg }}"
+    success_msg: "{{ nfs_node_group_success_msg }}"
+  when: groups['nfs_node']

+ 13 - 4
roles/cluster_validation/vars/main.yml

@@ -1,4 +1,4 @@
-#  Copyright 2020 Dell Inc. or its subsidiaries. All Rights Reserved.
+#  Copyright 2021 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.
@@ -12,7 +12,8 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 ---
-#Usage: fetch_password.yml
+
+# Usage: fetch_password.yml
 config_filename: "omnia_config.yml"
 config_vaultname: .omnia_vault_key
 min_length: 8
@@ -39,7 +40,7 @@ input_config_failure_msg: "Input parameters cannot be empty"
 login_node_required_success_msg: "Login_node_required successfully validated"
 login_node_required_fail_msg: "Failed. login_node_required can be either true or false"
 
-#Usage: validations.yml
+# Usage: validations.yml
 skip_tag_fail_msg: "Can't skip both slurm and kubernetes"
 manager_group_fail_msg: "manager group should contain exactly 1 node"
 manager_group_success_msg: "manager group check passed"
@@ -48,4 +49,12 @@ compute_group_success_msg: "compute group check passed"
 disjoint_fail_msg: "manager and compute groups should be disjoint"
 disjoint_success_msg: "manager and compute groups are disjoint"
 login_node_group_fail_msg: "Login node group should contain atleast 1 node when login_node_required is true"
-login_node_group_success_msg: "Login node group check passed when login_node_required is true"
+login_node_group_success_msg: "Login node group check passed when login_node_required is true"
+nfs_node_group_fail_msg: "nfs_node group should contain exactly 1 node"
+nfs_node_group_success_msg: "nfs_node group check passed"
+
+# Usage: fetch_powervault_status.yml
+tower_config_path: "{{ playbook_dir }}/control_plane/roles/webui_awx/files/.tower_cli.cfg"
+tower_vault_path: "{{ playbook_dir }}/control_plane/roles/webui_awx/files/.tower_vault_key"
+powervault_inventory_name: "powervault_me4_inventory"
+powervault_group: "powervault_me4"