main.yml 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. # Copyright 2022 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. - block:
  16. - name: Check if {{ tower_config_file }} file is encrypted
  17. command: cat {{ tower_config_file }}
  18. changed_when: false
  19. no_log: true
  20. register: config_content
  21. - name: Decrpyt {{ tower_config_file }}
  22. command: >-
  23. ansible-vault decrypt {{ tower_config_file }}
  24. --vault-password-file {{ tower_vault_file }}
  25. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  26. changed_when: false
  27. - name: Change file permissions
  28. file:
  29. path: "{{ tower_config_file }}"
  30. mode: "{{ file_perm }}"
  31. - name: Fetch awx host
  32. command: grep "host:" "{{ tower_config_file }}"
  33. changed_when: false
  34. register: fetch_awx_host
  35. - name: Fetch awx password
  36. command: grep "password:" "{{ tower_config_file }}"
  37. changed_when: false
  38. no_log: true
  39. register: fetch_awx_password
  40. - name: Set awx variables
  41. set_fact:
  42. awx_host: "{{ fetch_awx_host.stdout | regex_replace('host: ','') }}"
  43. awx_password: "{{ fetch_awx_password.stdout | regex_replace('password: ','') }}"
  44. no_log: true
  45. - name: Launch dynamic inventory
  46. block:
  47. - name: Launch device inventory job template
  48. awx.awx.tower_job_launch:
  49. job_template: "{{ device_inventory_template }}"
  50. tower_config_file: "{{ tower_config_file }}"
  51. wait: yes
  52. timeout: "{{ awx_max_wait_time }}"
  53. register: inventory_job_status
  54. rescue:
  55. - name: Restart awx pod
  56. command: kubectl rollout restart deployment awx -n awx
  57. changed_when: false
  58. when:
  59. - inventory_job_status.status is defined
  60. - '"pending" in inventory_job_status.status'
  61. - name: Wait for the awx pod to be up and running
  62. wait_for:
  63. timeout: "{{ pod_restart_time }}"
  64. when:
  65. - inventory_job_status.status is defined
  66. - '"pending" in inventory_job_status.status'
  67. - name: Launch device inventory job template
  68. awx.awx.tower_job_launch:
  69. job_template: "{{ device_inventory_template }}"
  70. tower_config_file: "{{ tower_config_file }}"
  71. wait: yes
  72. timeout: "{{ awx_max_wait_time }}"
  73. when:
  74. - inventory_job_status.status is defined
  75. - '"pending" in inventory_job_status.status'
  76. - name: Warning message for device inventory template
  77. debug:
  78. msg: "{{ device_inventory_template_warn_msg }}"
  79. when:
  80. - inventory_job_status.status is defined
  81. - '"pending" not in inventory_job_status.status'
  82. - name: Configure TOR Switches
  83. block:
  84. - name: Launch ethernet job template for TOR switches
  85. awx.awx.tower_job_launch:
  86. job_template: "{{ ethernet_job_template }}"
  87. tower_config_file: "{{ tower_config_file }}"
  88. wait: yes
  89. timeout: "{{ awx_max_wait_time }}"
  90. register: ethernet_job_status
  91. rescue:
  92. - name: Warning message for ethernet template
  93. debug:
  94. msg: "{{ ethernet_template_warn_msg }}"
  95. when: ethernet_switch_support
  96. - name: Wait for 15 mins for DHCP to assign IP to devices
  97. wait_for:
  98. timeout: "{{ dhcp_wait_time }}"
  99. when: device_config_support
  100. - name: Launch device inventory job template
  101. awx.awx.tower_job_launch:
  102. job_template: "{{ device_inventory_template }}"
  103. tower_config_file: "{{ tower_config_file }}"
  104. wait: yes
  105. timeout: "{{ awx_max_wait_time }}"
  106. register: inventory_job_status
  107. - name: Execute ethernet template
  108. block:
  109. - name: Launch ethernet job template for all switches
  110. awx.awx.tower_job_launch:
  111. job_template: "{{ ethernet_job_template }}"
  112. tower_config_file: "{{ tower_config_file }}"
  113. wait: yes
  114. timeout: "{{ awx_max_wait_time }}"
  115. register: ethernet_job_status
  116. rescue:
  117. - name: Warning message for ethernet template
  118. debug:
  119. msg: "{{ ethernet_template_warn_msg }}"
  120. when: ethernet_switch_support
  121. - name: Execute infiniband template
  122. block:
  123. - name: Launch infiniband job template
  124. awx.awx.tower_job_launch:
  125. job_template: "{{ infiniband_job_template }}"
  126. tower_config_file: "{{ tower_config_file }}"
  127. wait: yes
  128. timeout: "{{ awx_max_wait_time }}"
  129. register: ib_job_status
  130. rescue:
  131. - name: Warning message for infiniband template
  132. debug:
  133. msg: "{{ infiniband_template_warn_msg }}"
  134. when: ib_switch_support
  135. - name: Execute powervault_me4 template
  136. block:
  137. - name: Launch powervault_me4 job template
  138. awx.awx.tower_job_launch:
  139. job_template: "{{ powervault_me4_job_template }}"
  140. tower_config_file: "{{ tower_config_file }}"
  141. wait: yes
  142. timeout: "{{ awx_max_wait_time }}"
  143. register: powervault_job_status
  144. rescue:
  145. - name: Warning message for powervault_me4 template
  146. debug:
  147. msg: "{{ powervault_template_warn_msg }}"
  148. when: powervault_support
  149. - name: Execute idrac template
  150. block:
  151. - name: Launch idrac job template
  152. awx.awx.tower_job_launch:
  153. job_template: "{{ idrac_job_template }}"
  154. tower_config_file: "{{ tower_config_file }}"
  155. wait: yes
  156. register: idrac_job_status
  157. rescue:
  158. - name: Warning message for idrac template
  159. debug:
  160. msg: "{{ idrac_template_warn_msg }}"
  161. - name: Wait for 30 mins for idrac provisioning to be completed and inventory to be updated in AWX
  162. wait_for:
  163. timeout: "{{ provisioning_wait_time }}"
  164. when: host_mapping_file
  165. - name: Check the host_mapping_file_path output
  166. command: cat {{ host_mapping_file_path }}
  167. changed_when: false
  168. register: mapping_file
  169. when: host_mapping_file
  170. - name: Group the hosts in node_inventory when mapping file is present
  171. include_tasks: "{{ role_path }}/tasks/group_inventory.yml"
  172. when: host_mapping_file and component_role_support
  173. - name: Launch deploy_omnia job template
  174. awx.awx.tower_job_launch:
  175. job_template: "{{ component_role_job_template }}"
  176. tower_config_file: "{{ tower_config_file }}"
  177. wait: yes
  178. register: component_role_job_status
  179. when: host_mapping_file and component_role_support
  180. - name: Create awx job template for configuring new devices
  181. awx.awx.tower_job_template:
  182. name: "{{ item.name }}"
  183. job_type: "run"
  184. organization: "{{ awx_organization }}"
  185. inventory: "{{ item.inventory }}"
  186. project: "{{ project_name }}"
  187. playbook: "{{ item.playbook }}"
  188. credentials:
  189. - "{{ item.credential }}"
  190. state: present
  191. tower_config_file: "{{ tower_config_file }}"
  192. loop: "{{ job_template_details }}"
  193. - name: Build a schedule for configure new devices
  194. awx.awx.tower_schedule:
  195. name: "{{ item.name }}"
  196. unified_job_template: "{{ item.template }}"
  197. rrule: "{{ item.rrule }}"
  198. state: present
  199. tower_config_file: "{{ tower_config_file }}"
  200. loop: "{{ scheduled_template }}"
  201. - name: Encrypt {{ tower_config_file }}
  202. command: >-
  203. ansible-vault encrypt {{ tower_config_file }}
  204. --vault-password-file {{ tower_vault_file }}
  205. changed_when: false
  206. - name: Change file permissions
  207. file:
  208. path: "{{ tower_config_file }}"
  209. mode: "{{ file_perm }}"
  210. when : device_support_status