check_prerequisites.yml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. # Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. ---
  15. - name: Include control_plane_common vars
  16. include_vars: ../../control_plane_common/vars/main.yml
  17. run_once: true
  18. - name: Include custom_iso vars
  19. include_vars: ../../control_plane_customiso/vars/main.yml
  20. run_once: true
  21. - name: Check {{ management_station_ip_file }} file is present
  22. stat:
  23. path: "{{ role_path }}/files/{{ management_station_ip_file }}"
  24. register: ip_file_check
  25. run_once: true
  26. - name: Fetch management station ip from {{ management_station_ip_file }}
  27. command: cat {{ role_path }}/files/{{ management_station_ip_file }}
  28. changed_when: false
  29. register: fetch_ip
  30. run_once: true
  31. when: ip_file_check.stat.exists
  32. - name: Missing {{ management_station_ip_file }}
  33. fail:
  34. msg: "{{ missing_ip_file_fail_msg }}"
  35. when: not ip_file_check.stat.exists
  36. - name: Set management_station_ip
  37. set_fact:
  38. management_station_ip: "{{ fetch_ip.stdout }}"
  39. - name: Check NFS share access
  40. idrac_server_config_profile:
  41. idrac_ip: "{{ inventory_hostname }}"
  42. idrac_user: "{{ idrac_username }}"
  43. idrac_password: "{{ idrac_password }}"
  44. share_name: "{{ management_station_ip }}:{{ nfs_share_offline_repo }}"
  45. command: "export"
  46. scp_components: "BIOS"
  47. scp_file: "{{ nfs_check_file }}"
  48. export_format: XML
  49. export_use: Default
  50. job_wait: true
  51. register: nfs_check
  52. ignore_errors: true
  53. until: not nfs_check.failed
  54. retries: 3
  55. - name: Missing entries in nfs exports
  56. fail:
  57. msg: "{{ missing_exports_fail_msg }}"
  58. when:
  59. - nfs_check_key in nfs_check.msg or
  60. nfs_check_key in nfs_check.scp_status.Status
  61. - name: Initialize variables
  62. set_fact:
  63. raid_type: false
  64. raid_controller_sensor: ""
  65. raid_enclosure_name: ""
  66. drives_id: ""
  67. enterprise_license: false
  68. datacenter_license: false
  69. provision_status: false
  70. model_status: false
  71. - block:
  72. - name: Check tower_cli.cfg is encrypted
  73. command: cat "{{ playbook_dir }}/roles/webui_awx/files/{{ awx_vars_filename }}"
  74. changed_when: false
  75. register: awx_content
  76. run_once: true
  77. - name: Decrpyt tower_cli.cfg
  78. command: >-
  79. ansible-vault decrypt "{{ playbook_dir }}/roles/webui_awx/files/{{ awx_vars_filename }}"
  80. --vault-password-file "{{ playbook_dir }}/roles/webui_awx/files/{{ awx_vaultname }}"
  81. changed_when: false
  82. run_once: true
  83. when: "'$ANSIBLE_VAULT;' in awx_content.stdout"
  84. - name: Fetch awx host
  85. command: grep "host:" "{{ playbook_dir }}/roles/webui_awx/files/{{ awx_vars_filename }}"
  86. register: fetch_awx_host
  87. changed_when: false
  88. run_once: true
  89. - name: Fetch awx username
  90. command: grep "username:" "{{ playbook_dir }}/roles/webui_awx/files/{{ awx_vars_filename }}"
  91. register: fetch_awx_username
  92. changed_when: false
  93. run_once: true
  94. no_log: true
  95. - name: Fetch awx password
  96. command: grep "password:" "{{ playbook_dir }}/roles/webui_awx/files/{{ awx_vars_filename }}"
  97. register: fetch_awx_password
  98. changed_when: false
  99. run_once: true
  100. no_log: true
  101. - name: Set awx variables
  102. set_fact:
  103. awx_host: "{{ fetch_awx_host.stdout | regex_replace('host: ','') }}"
  104. awx_username: "{{ fetch_awx_username.stdout | regex_replace('username: ','') }}"
  105. awx_password: "{{ fetch_awx_password.stdout | regex_replace('password: ','') }}"
  106. no_log: true
  107. - name: Encrypt tower_cli.cfg
  108. command: >-
  109. ansible-vault encrypt "{{ playbook_dir }}/roles/webui_awx/files/{{ awx_vars_filename }}"
  110. --vault-password-file "{{ playbook_dir }}/roles/webui_awx/files/{{ awx_vaultname }}"
  111. changed_when: false
  112. run_once: true
  113. when: "'$ANSIBLE_VAULT;' in awx_content.stdout"
  114. - name: Get inventory list
  115. command: >-
  116. awx --conf.host "{{ awx_host }}" --conf.username "{{ awx_username }}" --conf.password "{{ awx_password }}"
  117. inventory list -f human --filter "name"
  118. register: inventory_list
  119. run_once: true
  120. changed_when: false
  121. no_log: true
  122. - name: Create provisioned_idrac inventory
  123. command: >-
  124. awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
  125. inventory create --name "{{ provisioned_idrac_inventory_name }}" --organization "{{ awx_organization }}"
  126. register: create_inventory
  127. run_once: true
  128. changed_when: true
  129. no_log: true
  130. when: provisioned_idrac_inventory_name not in inventory_list.stdout
  131. - name: Fetch provisioned_idrac inventory
  132. command: >-
  133. awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
  134. hosts list --inventory "{{ provisioned_idrac_inventory_name }}" -f human --filter "name"
  135. register: fetch_inventory
  136. run_once: true
  137. changed_when: false
  138. no_log: true
  139. - name: Set provision status
  140. set_fact:
  141. provision_status: true
  142. when: inventory_hostname in fetch_inventory.stdout
  143. - name: Removing hosts already provisioned
  144. debug:
  145. msg: "{{ provision_skip_msg }}"
  146. when: provision_status
  147. when: awx_search_key in hostname.stdout
  148. - block:
  149. - name: Show status of the Lifecycle Controller
  150. dellemc.openmanage.idrac_lifecycle_controller_status_info:
  151. idrac_ip: "{{ inventory_hostname }}"
  152. idrac_user: "{{ idrac_username }}"
  153. idrac_password: "{{ idrac_password }}"
  154. register: lc_check_status
  155. - name: LC not available
  156. fail:
  157. msg: "{{ lc_check_fail_msg }}"
  158. when: not lc_check_status.lc_status_info.LCReady
  159. register: lc_fail
  160. - name: Get system inventory
  161. dellemc.openmanage.idrac_system_info:
  162. idrac_ip: "{{ inventory_hostname }}"
  163. idrac_user: "{{ idrac_username }}"
  164. idrac_password: "{{ idrac_password }}"
  165. register: idrac_info
  166. - name: Set enterprise license status
  167. set_fact:
  168. enterprise_license: true
  169. with_items: "{{ idrac_info.system_info.License }}"
  170. when:
  171. - '"iDRAC" in idrac_info.system_info.License[my_idx1].LicenseDescription'
  172. - '"Enterprise" in idrac_info.system_info.License[my_idx1].LicenseDescription'
  173. - '"License" in idrac_info.system_info.License[my_idx1].LicenseDescription'
  174. - '"Healthy" in idrac_info.system_info.License[my_idx1].PrimaryStatus'
  175. loop_control:
  176. index_var: my_idx1
  177. - name: Set datacenter license status
  178. set_fact:
  179. datacenter_license: true
  180. with_items: "{{ idrac_info.system_info.License }}"
  181. when:
  182. - '"iDRAC" in idrac_info.system_info.License[my_idx2].LicenseDescription'
  183. - '"Datacenter" in idrac_info.system_info.License[my_idx2].LicenseDescription'
  184. - '"License" in idrac_info.system_info.License[my_idx2].LicenseDescription'
  185. - '"Healthy" in idrac_info.system_info.License[my_idx2].PrimaryStatus'
  186. loop_control:
  187. index_var: my_idx2
  188. when: not provision_status