main.yml 7.4 KB

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