Browse Source

Issue #531: Node inventory updation and device inventory creation

Signed-off-by: trinesh <palakurthi_trinesh@dellteam.com>
Trinesh Palakurthi 3 years ago
parent
commit
866167d2d9

+ 2 - 1
.all-contributorsrc

@@ -18,7 +18,8 @@
         "ideas",
         "maintenance",
         "mentoring",
-        "design"
+        "design",
+        "review"
       ]
     },
     {

File diff suppressed because it is too large
+ 1 - 1
README.md


+ 6 - 3
control_plane/collect_device_info.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,9 +12,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 ---
-- name: Dynamic Inventory
+
+- name: Collect control_plane device inventory
   hosts: localhost
   connection: local
-  gather_facts: no
+  gather_facts: false
   roles:
     - collect_device_info
+
+- import_playbook: "{{ playbook_dir }}/roles/collect_device_info/files/create_inventory.yml"

+ 4 - 3
control_plane/collect_node_info.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,9 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 ---
-- name: Dynamic Inventory
+
+- name: Collect control_plane host inventory
   hosts: localhost
   connection: local
   gather_facts: no
   roles:
-    - collect_node_info
+    - collect_node_info

+ 369 - 0
control_plane/roles/collect_device_info/files/create_inventory.yml

@@ -0,0 +1,369 @@
+# 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.
+
+---
+
+# This role will not group the devices if user provides invalid credentials
+
+- name: Create inventory in awx
+  hosts: device_inventory
+  connection: local
+  gather_facts: false
+  tasks:
+    - name: Include collect_device_info vars
+      include_vars: "{{ playbook_dir }}/../vars/main.yml"
+      run_once: true
+
+    - name: Include variable file base_vars.yml
+      include_vars: "{{ base_vars_file }}"
+      run_once: true
+
+    - name: Check if tower_config_file file is encrypted
+      command: cat "{{ playbook_dir }}/../../webui_awx/files/.tower_cli.cfg"
+      changed_when: false
+      no_log: true
+      register: tower_config_content
+      run_once: true
+
+    - name: Decrypt tower_config_file
+      command: >-
+        ansible-vault decrypt "{{ playbook_dir }}/../../webui_awx/files/.tower_cli.cfg"
+        --vault-password-file "{{ playbook_dir }}/../../webui_awx/files/.tower_vault_key"
+      changed_when: false
+      when: "'$ANSIBLE_VAULT;' in tower_config_content.stdout"
+      run_once: true
+
+    - name: Change file permissions
+      file:
+        path: "{{ playbook_dir }}/../../webui_awx/files/.tower_cli.cfg"
+        mode: "{{ file_perm }}"
+      run_once: true
+
+    - name: Fetch awx host
+      command: grep "host:" "{{ playbook_dir }}/../../webui_awx/files/.tower_cli.cfg"
+      register: fetch_awx_host
+      changed_when: false
+      run_once: true
+
+    - name: Fetch awx username
+      command: grep "username:" "{{ playbook_dir }}/../../webui_awx/files/.tower_cli.cfg"
+      register: fetch_awx_username
+      changed_when: false
+      run_once: true
+      no_log: true
+
+    - name: Fetch awx password
+      command: grep "password:" "{{ playbook_dir }}/../../webui_awx/files/.tower_cli.cfg"
+      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_config_file
+      command: >-
+        ansible-vault encrypt "{{ playbook_dir }}/../../webui_awx/files/.tower_cli.cfg"
+        --vault-password-file "{{ playbook_dir }}/../../webui_awx/files/.tower_vault_key"
+      changed_when: false
+      when: "'$ANSIBLE_VAULT;' in tower_config_content.stdout"
+      run_once: true
+
+    - name: Change file permissions
+      file:
+        path: "{{ playbook_dir }}/../../webui_awx/files/.tower_cli.cfg"
+        mode: "{{ file_perm }}"
+      run_once: true
+
+    - name: Check if {{ login_vars_file }} file is encrypted
+      command: cat {{ login_vars_file }}
+      changed_when: false
+      no_log: true
+      register: config_content
+      run_once: true
+
+    - name: Decrpyt {{ login_vars_file }}
+      command: >-
+        ansible-vault decrypt {{ login_vars_file }}
+        --vault-password-file {{ login_vault_file }}
+      when: "'$ANSIBLE_VAULT;' in config_content.stdout"
+      changed_when: false
+      run_once: true
+
+    - name: Include variable file {{ login_vars_file }}
+      include_vars: "{{ login_vars_file }}"
+      no_log: true
+      run_once: true
+
+    - name: Encrypt {{ login_vars_file }}
+      command: >-
+        ansible-vault encrypt {{ login_vars_file }}
+        --vault-password-file {{ login_vault_file }}
+      changed_when: false
+      when: "'$ANSIBLE_VAULT;' in config_content.stdout"
+      run_once: true
+
+    - name: Initialize variables
+      set_fact:
+        idrac_inventory_status: false
+        ethernet_inventory_status: false
+        ib_inventory_status: false
+        powervault_me4_status: false
+
+    - name: idrac_inventory validation tasks
+      block:
+        - name: Fetch the hosts in idrac_inventory
+          command: >-
+            awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
+            --conf.insecure hosts list --inventory idrac_inventory -f human --filter "name"
+          changed_when: false
+          no_log: true
+          run_once: true
+          register: idrac_hosts
+
+        - name: Assert idrac IP
+          dellemc.openmanage.idrac_system_info:
+            idrac_ip: "{{ inventory_hostname }}"
+            idrac_user: "{{ idrac_username }}"
+            idrac_password: "{{ idrac_password }}"
+          register: idrac_info
+          when: inventory_hostname not in idrac_hosts.stdout
+
+        - name: Set idrac_inventory_status
+          set_fact:
+            idrac_inventory_status: true
+          when:
+            - inventory_hostname not in idrac_hosts.stdout
+            - idrac_search_key in idrac_info.system_info.iDRAC[0].ProductInfo
+      rescue:
+        - name: Failed while adding device to idrac_inventory
+          debug:
+            msg: "{{ idrac_inventory_fail_msg }}"
+      when: not idrac_inventory_status
+
+    - name: Add host to awx idrac_inventory
+      block:
+        - name: Add the host to awx idrac_inventory if not present
+          command: >-
+            awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
+            --conf.insecure hosts create --name {{ inventory_hostname }} --inventory idrac_inventory
+          changed_when: true
+          no_log: true
+      rescue:
+        - name: Failed while adding device to idrac_inventory
+          debug:
+            msg: "{{ idrac_inventory_fail_msg }}"
+      when: idrac_inventory_status
+
+    - name: ethernet_inventory validation tasks
+      block:
+        - name: Fetch the hosts in ethernet inventory
+          command: >-
+            awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
+            --conf.insecure hosts list --inventory ethernet_inventory -f human --filter "name"
+          changed_when: false
+          no_log: true
+          run_once: true
+          register: ethernet_switches
+
+        - name: Assert ethernet switch
+          dellos10_command:
+            provider:
+              host: "{{ inventory_hostname }}"
+              username: "{{ ethernet_switch_username }}"
+              password: "{{ ethernet_switch_password }}"
+            commands: ['show version']
+          when: inventory_hostname not in ethernet_switches.stdout
+          register: dellswitch_info
+          no_log: true
+
+        - name: Set ethernet_inventory_status
+          set_fact:
+            ethernet_inventory_status: true
+          when:
+            - inventory_hostname not in ethernet_switches.stdout
+            - dellswitch_info.stdout | regex_search(ethernet_search_key)
+      rescue:
+        - name: Failed while adding device to ethernet_inventory
+          debug:
+            msg: "{{ ethernet_inventory_fail_msg }}"
+      when:
+        - not idrac_inventory_status
+        - not ethernet_inventory_status
+        - inventory_hostname not in idrac_hosts.stdout
+
+    - name: Add the host to awx ethernet inventory
+      block:
+        - name: Add the host to awx ethernet inventory if not present
+          command: >-
+            awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
+            --conf.insecure hosts create --name {{ inventory_hostname }} --inventory ethernet_inventory
+          changed_when: true
+          no_log: true
+      rescue:
+        - name: Failed while adding device to ethernet_inventory
+          debug:
+            msg: "{{ ethernet_inventory_fail_msg }}"
+      when: ethernet_inventory_status
+
+    - name: ib_inventory validation tasks
+      block:
+        - name: Fetch the hosts in infiniband inventory
+          command: >-
+            awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
+            --conf.insecure hosts list --inventory infiniband_inventory -f human --filter "name"
+          changed_when: false
+          no_log: true
+          run_once: true
+          register: infiniband_switches
+
+        - name: Authenticate infiniband Switch
+          uri:
+            url: http://{{ inventory_hostname }}/admin/launch?script=rh&template=login&action=login
+            method: POST
+            body_format: form-urlencoded
+            body:
+              f_user_id: "{{ ib_username }}"
+              f_password: "{{ ib_password }}"
+              enter: Sign in
+            status_code: "{{ infiniband_status_code }}"
+          no_log: true
+          register: login
+          when: inventory_hostname not in infiniband_switches.stdout
+
+        - name: Assert infiniband switch
+          uri:
+            url: http://{{ inventory_hostname }}/admin/launch?script=json
+            method: POST
+            body_format: json
+            headers:
+              Cookie: "{{ login.set_cookie.split(';')[0] }}"
+            body:
+              {
+              "commands":
+              [
+                "show version"
+              ]
+              }
+          register: infinibandswitch_info
+          when:
+            - inventory_hostname not in infiniband_switches.stdout
+            - not login.failed
+
+        - name: Set ib_inventory_status
+          set_fact:
+            ib_inventory_status: true
+          when:
+            - inventory_hostname not in infiniband_switches.stdout
+            - not login.failed
+            - infinibandswitch_info.json.data['Product name'] == infiniband_search_key
+      rescue:
+        - name: Failed while adding device to ib_inventory
+          debug:
+            msg: "{{ ib_inventory_fail_msg }}"
+      when:
+        - not idrac_inventory_status
+        - not ethernet_inventory_status
+        - not ib_inventory_status
+        - inventory_hostname not in idrac_hosts.stdout
+
+    - name: Add the host to awx infiniband_inventory
+      block:
+        - name: Add the host to awx infiniband_inventory if not present
+          command: >-
+            awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
+            --conf.insecure hosts create --name {{ inventory_hostname }} --inventory infiniband_inventory
+          changed_when: true
+          no_log: true
+      rescue:
+        - name: Failed while adding device to ib_inventory
+          debug:
+            msg: "{{ ib_inventory_fail_msg }}"
+      when: ib_inventory_status
+
+    - name: powervault_me4_inventory validation tasks
+      block:
+        - name: Fetch the hosts in powervault me4 inventory
+          command: >-
+            awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
+            --conf.insecure hosts list --inventory powervault_me4_inventory -f human --filter "name"
+          changed_when: false
+          no_log: true
+          run_once: true
+          register: me4_storage
+
+        - name: Get auth string for powervault
+          shell: echo -n {{ powervault_me4_username }}_{{ powervault_me4_password }} | sha256sum
+          changed_when: false
+          register: auth_string
+          no_log: true
+          when: inventory_hostname not in me4_storage.stdout
+
+        - name: Get session key for powervault
+          uri:
+            url: https://{{ inventory_hostname }}/api/login/{{ auth_string.stdout | replace(" -", "") }}
+            method: GET
+            headers:
+              {'datatype': 'json'}
+            validate_certs: no
+          register: session_key
+          when: inventory_hostname not in me4_storage.stdout
+
+        - name: Assert me4_powervault
+          uri:
+            url: https://{{ inventory_hostname }}/api/show/system
+            method: GET
+            body_format: json
+            validate_certs: no
+            use_proxy: no
+            headers:
+              {'sessionKey': "{{ session_key.json.status[0].response }}", 'datatype':'json'}
+          register: system_info
+          when: inventory_hostname not in me4_storage.stdout
+
+        - name: Set powervault_me4_status
+          set_fact:
+            powervault_me4_status: true
+          when:
+            - inventory_hostname not in me4_storage.stdout
+            - me4_powervault_search_key in system_info.json.system[0]['scsi-product-id']
+      rescue:
+        - name: Failed while adding device to powervault_me4_inventory
+          debug:
+            msg: "{{ powervault_me4_fail_msg }}"
+      when:
+        - not idrac_inventory_status
+        - not ethernet_inventory_status
+        - not ib_inventory_status
+        - not powervault_me4_status
+        - inventory_hostname not in idrac_hosts.stdout
+
+    - name: Add the host to awx powervault_me4_inventory
+      block:
+        - name: Add the host to awx powervault_me4_inventory if not present
+          command: >-
+            awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
+            --conf.insecure hosts create --name {{ inventory_hostname }} --inventory powervault_me4_inventory
+          changed_when: true
+          no_log: true
+      rescue:
+        - name: Failed while adding device to powervault_me4_inventory
+          debug:
+            msg: "{{ powervault_me4_fail_msg }}"
+      when: powervault_me4_status

+ 30 - 13
control_plane/roles/collect_device_info/tasks/main.yml

@@ -1,19 +1,36 @@
 # 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
+# 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
+#     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.
+# 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.
+
+# This role will not group the devices if user provides invalid credentials
 ---
 
-# Will be updated later in each PR
-- name: Pass
-  debug:
-    msg: "Pass"
+- name: Check if provisioned host file exists
+  stat:
+    path: "{{ mgmt_provisioned_hosts_file }}"
+  register: provisioned_file
+
+- name: Check the mgmt_provisioned_hosts_file output
+  command: cat {{ mgmt_provisioned_hosts_file }}
+  changed_when: false
+  register: mgmt_hosts
+  when: provisioned_file.stat.exists
+
+- name: Create device_inventory
+  add_host:
+    name: "{{ item }}"
+    groups: "device_inventory"
+  with_items: "{{ mgmt_hosts.stdout_lines }}"
+  when: 
+    - provisioned_file.stat.exists
+    - item | trim | length > 1

+ 36 - 0
control_plane/roles/collect_device_info/vars/main.yml

@@ -0,0 +1,36 @@
+# 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.
+
+---
+
+# vars file for collect_device_info role
+# This role will not group the devices if user provides invalid credentials
+
+# Usage main.yml
+mgmt_provisioned_hosts_file: "{{ role_path }}/files/mgmt_provisioned_hosts.yml"
+
+# Usage create_inventory.yml
+infiniband_status_code: 302
+idrac_search_key: "Integrated Dell Remote Access Controller"
+ethernet_search_key: "OS10"
+infiniband_search_key: "MLNX-OS"
+me4_powervault_search_key: "ME4"
+idrac_inventory_fail_msg: "Failed. Unable to add {{ inventory_hostname }} to idrac_inventory"
+ethernet_inventory_fail_msg:  "Failed. Unable to add {{ inventory_hostname }} to ethernet_inventory"
+ib_inventory_fail_msg: "Failed. Unable to add {{ inventory_hostname }} to ib_inventory"
+powervault_me4_fail_msg: "Failed. Unable to add {{ inventory_hostname }} to powervault_me4_inventory"
+base_vars_file: "{{ playbook_dir }}/../../../input_params/base_vars.yml"
+login_vars_file: "{{ playbook_dir }}/../../../input_params/login_vars.yml"
+login_vault_file: "{{ playbook_dir }}/../../../input_params/.login_vault_key"
+file_perm: '0644'

+ 21 - 17
control_plane/roles/collect_node_info/files/add_host.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,36 +12,40 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 ---
-
-- name: Check if host already exists
-  command: awk "{{ '/'+ item + '/' }}" /root/inventory
-  register: check_host
-  changed_when: no
-
 - name: Initialise host description
   set_fact:
     host_description: "Description Unavailable"
-
+    
 - name: Fetch description
   set_fact:
     host_description: "CPU:{{ hostvars[item]['ansible_processor_count'] }}
     Cores:{{ hostvars[item]['ansible_processor_cores'] }}
     Memory:{{ hostvars[item]['ansible_memtotal_mb'] }}MB
     BIOS:{{ hostvars[item]['ansible_bios_version'] }}"
-  when: not check_host.stdout | regex_search(item)
   ignore_errors: yes
 
-- name: Add host
-  lineinfile:
-    path:  "/root/inventory"
-    line: "    {{ item }}:\n      _awx_description: {{ host_description }}"
+- name: Fetch the hosts in awx node inventory
+  command: >-
+    awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
+    --conf.insecure hosts list --inventory node_inventory
+  changed_when: false
+  no_log: true
   when:
-    - not check_host.stdout | regex_search(item)
-    - host_description != "Description Unavailable"
+     - host_description != "Description Unavailable"
+  register: hosts
+  ignore_errors: yes
+  
+- name: Add the host to awx node inventory if not present
+  command: >-
+    awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
+    --conf.insecure hosts create --name {{ item }} --inventory node_inventory
+  changed_when: true
+  when: item not in hosts.stdout
+  no_log: true
+  ignore_errors: yes
 
 - name: Host added msg
   debug:
     msg: "{{ host_added_msg + item }}"
   when:
-    - not check_host.stdout | regex_search(item)
-    - host_description != "Description Unavailable"
+    - host_description != "Description Unavailable"

+ 99 - 22
control_plane/roles/collect_node_info/files/create_inventory.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,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 ---
-
 - name: Find reachable hosts
   hosts: all
   gather_facts: false
@@ -44,14 +43,29 @@
     - name: Include vars file of inventory role
       include_vars: ../vars/main.yml
 
-- name: Set hostname on reachable nodes and gather facts
+    - name: Check if omnia config file is encrypted
+      command: "cat {{ omnia_config_file }}"
+      changed_when: false
+      register: config_content
+      #no_log: True
+
+    - name: Decrpyt omnia_config.yml
+      command: >-
+        ansible-vault decrypt "{{ omnia_config_file }}"
+        --vault-password-file "{{ omnia_config_vault_file }}"
+      when: "'$ANSIBLE_VAULT;' in config_content.stdout"
+
+    - name: Include vars file of inventory role
+      include_vars: "{{ omnia_config_file }}"
+
+- name: Set hostname for reachable nodes and gather facts
   hosts: reachable
   gather_facts: False
   ignore_unreachable: true
-  remote_user: "{{ cobbler_username }}"
+  remote_user: "{{ host_username }}"
   vars:
-    ansible_password: "{{ cobbler_password }}"
-    ansible_become_pass: "{{ cobbler_password }}"
+    ansible_password: "{{ host_password }}"
+    ansible_become_pass: "{{ host_password }}"
     ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
     mapping_file_present: ""
   tasks:
@@ -65,21 +79,21 @@
       changed_when: false
       ignore_errors: true
 
-    - name: Check if IP present in mapping file
-      command: grep "{{ inventory_hostname }}" ../../provision/files/new_mapping_file.csv
+    - name: Check if IP is present in mapping file
+      command: grep "{{ inventory_hostname }}" ../../provision_cobbler/files/new_host_mapping_file.csv
       delegate_to: localhost
       register: file_present
       when: mapping_file | bool == true
       ignore_errors: true
 
-    - name: Set fact if mapping file present
+    - name: Set fact if mapping file is present
       set_fact:
         mapping_file_present: "{{ file_present.stdout }}"
       when: mapping_file | bool == true
       ignore_errors: true
 
     - name: Get the static hostname from mapping file
-      shell: awk -F',' '$3 == "{{ inventory_hostname }}" { print $2 }' ../../provision/files/new_mapping_file.csv
+      shell: awk -F',' '$3 == "{{ inventory_hostname }}" { print $2 }' ../../provision_cobbler/files/new_host_mapping_file.csv
       delegate_to: localhost
       when: ('localhost' in hostname_check.stdout) and (mapping_file_present != "" ) and ( mapping_file | bool == true )
       register: host_name
@@ -87,36 +101,34 @@
 
     - name: Set the hostname from mapping file
       hostname:
-        name: "{{ host_name.stdout }}"
+        name: "{{ host_name.stdout + '.' + hostvars['localhost']['domain_name'] }}"
       when: ('localhost' in hostname_check.stdout) and (mapping_file_present != "" ) and  (mapping_file | bool == true )
       ignore_errors: true
-    
+
     - name: Set the hostname if hostname not present mapping file
       hostname:
-        name: "compute{{ inventory_hostname.split('.')[-2] + '-' + inventory_hostname.split('.')[-1] }}"
+        name: "compute{{ inventory_hostname.split('.')[-2] + '-' + inventory_hostname.split('.')[-1] + '.' + hostvars['localhost']['domain_name'] }}"
       when: ('localhost' in hostname_check.stdout) and (file_present.rc != 0) and (mapping_file | bool == true )
       ignore_errors: true
 
     - name: Set the system hostname
       hostname:
-        name: "compute{{ inventory_hostname.split('.')[-2] + '-' + inventory_hostname.split('.')[-1] }}"
+        name: "compute{{ inventory_hostname.split('.')[-2] + '-' + inventory_hostname.split('.')[-1]+'.'+ hostvars['localhost']['domain_name'] }}"
       when: ('localhost' in hostname_check.stdout) and (mapping_file | bool == false)
       ignore_errors: true
 
     - name: Add new hostname to /etc/hosts from mapping file
       lineinfile:
         dest: /etc/hosts
-        regexp: '^127\.0\.0\.1[ \t]+localhost'
-        line: "127.0.0.1 localhost {{ host_name.stdout }}"
+        line: "{{ inventory_hostname }} {{ host_name.stdout + '.' + hostvars['localhost']['domain_name'] }}"
         state: present
       when: ('localhost' in hostname_check.stdout) and ( mapping_file_present != "" ) and ( mapping_file | bool == true )
       ignore_errors: true
 
-    - name: Add new hostname to /etc/hosts if hostname not present mapping fil
+    - name: Add new hostname to /etc/hosts if hostname not present mapping file
       lineinfile:
         dest: /etc/hosts
-        regexp: '^127\.0\.0\.1[ \t]+localhost'
-        line: "127.0.0.1 localhost compute{{ inventory_hostname.split('.')[-2] + '-' + inventory_hostname.split('.')[-1] }}"
+        line: "{{ inventory_hostname }} compute{{ inventory_hostname.split('.')[-2] + '-' + inventory_hostname.split('.')[-1]+'.'+ hostvars['localhost']['domain_name'] }}"
         state: present
       when: ('localhost' in hostname_check.stdout) and ( file_present.rc != 0 ) and ( mapping_file | bool == true )
       ignore_errors: true
@@ -124,8 +136,7 @@
     - name: Add new hostname to /etc/hosts
       lineinfile:
         dest: /etc/hosts
-        regexp: '^127\.0\.0\.1[ \t]+localhost'
-        line: "127.0.0.1 localhost compute{{ inventory_hostname.split('.')[-2] + '-' + inventory_hostname.split('.')[-1] }}"
+        line: "{{ inventory_hostname }} compute{{ inventory_hostname.split('.')[-2] + '-' + inventory_hostname.split('.')[-1] +'.'+ hostvars['localhost']['domain_name'] }}"
         state: present
       when: ('localhost' in hostname_check.stdout) and (mapping_file | bool == false )
       ignore_errors: true
@@ -135,6 +146,72 @@
   connection: local
   gather_facts: false
   tasks:
+    - name: Encrypt omnia_config.yml file
+      command: >-
+        ansible-vault encrypt "{{ omnia_config_file }}"
+        --vault-password-file "{{ omnia_config_vault_file }}"
+      changed_when: false
+
+    - name: Update omnia_config.yml permissions
+      file:
+        path: "{{ omnia_config_file }}"
+        mode: "{{ file_perm }}"
+
+    - name: Check if tower_config_file file is encrypted
+      command: cat "{{ playbook_dir }}/../../webui_awx/files/.tower_cli.cfg"
+      changed_when: false
+      no_log: true
+      register: tower_config_content
+      run_once: true
+
+    - name: Decrypt tower_config_file
+      command: >-
+        ansible-vault decrypt "{{ playbook_dir }}/../../webui_awx/files/.tower_cli.cfg"
+        --vault-password-file "{{ playbook_dir }}/../../webui_awx/files/.tower_vault_key"
+      changed_when: false
+      when: "'$ANSIBLE_VAULT;' in tower_config_content.stdout"
+      run_once: true
+
+    - name: Change file permissions
+      file:
+        path: "{{ playbook_dir }}/../../webui_awx/files/.tower_cli.cfg"
+        mode: "{{ file_perm }}"
+
+    - name: Fetch awx host
+      command: grep "host:" "{{ playbook_dir }}/../../webui_awx/files/.tower_cli.cfg"
+      register: fetch_awx_host
+      changed_when: false
+      run_once: true
+
+    - name: Fetch awx username
+      command: grep "username:" "{{ playbook_dir }}/../../webui_awx/files/.tower_cli.cfg"
+      register: fetch_awx_username
+      changed_when: false
+      run_once: true
+      no_log: true
+
+    - name: Fetch awx password
+      command: grep "password:" "{{ playbook_dir }}/../../webui_awx/files/.tower_cli.cfg"
+      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_config_file
+      command: >-
+        ansible-vault encrypt "{{ playbook_dir }}/../../webui_awx/files/.tower_cli.cfg"
+        --vault-password-file "{{ playbook_dir }}/../../webui_awx/files/.tower_vault_key"
+      changed_when: false
+      when: "'$ANSIBLE_VAULT;' in tower_config_content.stdout"
+      run_once: true
+
     - name: Update inventory file
       block:
         - name: Fetch facts and add new hosts
@@ -145,4 +222,4 @@
     - name: Show unreachable hosts
       debug:
         msg: "{{ host_unreachable_msg }} + {{ groups['ungrouped'] }}"
-      when: "'ungrouped' in groups"
+      when: "'ungrouped' in groups"

+ 42 - 52
control_plane/roles/collect_node_info/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.
@@ -16,85 +16,75 @@
   set_fact:
     ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
 
-- name: Check if provisioned host file exists
-  stat:
-    path: "{{ role_path }}/files/provisioned_hosts.yml"
-  register: provisioned_file_result
+- name: Fetch the execution environment
+  command: hostname
+  register: host_name
+  changed_when: false
 
-- name: Include vars file of control_plane_common role
-  include_vars: "{{ role_path }}/../control_plane_common/vars/main.yml"
-  no_log: True
+- name: Install sshpass
+  package:
+    name: sshpass
+    state: present
+  when: awx_search_key not in host_name.stdout
 
-- name: Include vars file of webui_awx role
-  include_vars: "{{ role_path }}/../webui_awx/vars/main.yml"
-  no_log: True
+- name: Check if provisioned host file exists
+  stat:
+    path: "{{ provisioned_hosts_file }}"
+  register: provisioned_file
 
-- name: Update inventory file
+- name: Include variable file base_vars.yml
+  include_vars: "{{ base_vars_file }}"
+  
+- name: Update inventory
   block:
-    - name: Check if input config file is encrypted
-      command: cat {{ input_config_filename }}
+    - name: Check if {{ login_vars_file }} file is encrypted
+      command: cat {{ login_vars_file }}
       changed_when: false
+      no_log: true
       register: config_content
+      run_once: true
 
-    - name: Decrpyt appliance_config.yml
+    - name: Decrpyt {{ login_vars_file }}
       command: >-
-        ansible-vault decrypt {{ input_config_filename }}
-        --vault-password-file {{ vault_filename }}
+        ansible-vault decrypt {{ login_vars_file }}
+        --vault-password-file {{ login_vault_file }}
       when: "'$ANSIBLE_VAULT;' in config_content.stdout"
+      changed_when: false
+      run_once: true
 
-    - name: Include variable file appliance_config.yml
-      include_vars: "{{ input_config_filename }}"
-      no_log: True
-
+    - name: Include variable file {{ login_vars_file }}
+      include_vars: "{{ login_vars_file }}"
+      no_log: true
+      run_once: true
+    
     - name: Save input variables from file
       set_fact:
-        cobbler_password: "{{ provision_password }}"
         mapping_file: false
-        path_mapping_file: "{{ mapping_file_path }}"
-      no_log: True
 
     - name: Check the status for mapping file
       set_fact:
         mapping_file: true
-      when: path_mapping_file != ""
+      when: host_mapping_file_path
 
-    - name: Encrypt input config file
+    - name: Encrypt {{ login_vars_file }}
       command: >-
-        ansible-vault encrypt {{ input_config_filename }}
-        --vault-password-file {{ vault_filename }}
+        ansible-vault encrypt {{ login_vars_file }}
+        --vault-password-file {{ login_vault_file }}
       changed_when: false
-
-    - name: Check if inventory file already exists
-      file:
-        path: "/root/inventory"
-        state: absent
-
-    - name: Create empty inventory file
-      copy:
-        dest:  "/root/inventory"
-        content: |
-          ---
-          all:
-            hosts:
-        owner: root
-        mode: 0775
+      when: "'$ANSIBLE_VAULT;' in config_content.stdout"
+      run_once: true
 
     - name: Add inventory playbook
       block:
         - name: add hosts with description to inventory file
           command: >-
-            ansible-playbook -i {{ role_path }}/files/provisioned_hosts.yml
+            ansible-playbook -i {{ provisioned_hosts_file }}
             {{ role_path }}/files/create_inventory.yml
-            --extra-vars "cobbler_username={{ cobbler_username }} cobbler_password={{ cobbler_password }} mapping_file={{ mapping_file | bool }}"
+            --extra-vars "host_username={{ host_username }} host_password={{ provision_password }} mapping_file={{ mapping_file | bool }}"
           no_log: True
           register: register_error
       rescue:
         - name: Fail if host addition was not successful
           fail:
-            msg: "{{ register_error.stderr + register_error.stdout | regex_replace(cobbler_username) | regex_replace(cobbler_password) }}"
-
-  when: provisioned_file_result.stat.exists
-
-- name: push inventory to AWX
-  command: awx-manage inventory_import --inventory-name {{ omnia_inventory_name }} --source /root/inventory
-  when: provisioned_file_result.stat.exists
+            msg: "{{ register_error.stderr + register_error.stdout | regex_replace(host_username) | regex_replace(provision_password) }}"
+  when: provisioned_file.stat.exists

+ 12 - 3
control_plane/roles/collect_node_info/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,5 +12,14 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 ---
-host_added_msg: "Added host to inventory: "
-host_unreachable_msg: "Following hosts are unreachable: "
+provisioned_hosts_file: "{{ role_path }}/files/provisioned_hosts.yml"
+base_vars_file: "{{ role_path }}/../../input_params/base_vars.yml"
+login_vars_file: "{{ role_path }}/../../input_params/login_vars.yml"
+login_vault_file: "{{ role_path }}/../../input_params/.login_vault_key"
+omnia_config_file: "../../../../omnia_config.yml"
+omnia_config_vault_file: "../../../../.omnia_vault_key"
+file_perm: '0644'
+host_username: root
+host_added_msg: "Added host to awx inventory: "
+host_unreachable_msg: "Following hosts are unreachable: "
+awx_search_key: awx