fetch_base_inputs.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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 base variable file base_vars.yml
  16. include_vars: "{{ base_vars_filename }}"
  17. no_log: true
  18. - name: Validate input parameters of base_vars are not empty
  19. fail:
  20. msg: "{{ input_base_failure_msg }}"
  21. register: input_base_check
  22. when:
  23. - ansible_conf_file_path | length < 1 or
  24. public_nic | length < 1 or
  25. appliance_k8s_pod_net_cidr | length < 1 or
  26. awx_organization | length < 1 or
  27. timezone | length < 1 or
  28. language | length < 1 or
  29. iso_file_path | length < 1 or
  30. mngmnt_network_nic | length < 1 or
  31. mngmnt_network_dhcp_start_range | length < 1 or
  32. mngmnt_network_dhcp_end_range | length < 1 or
  33. host_network_nic | length < 1 or
  34. host_network_dhcp_start_range | length < 1 or
  35. host_network_dhcp_end_range | length < 1 or
  36. provision_method | length < 1 or
  37. default_lease_time | length < 1
  38. - name: Validate default lease time
  39. assert:
  40. that:
  41. - default_lease_time|int
  42. - default_lease_time|int <= 31536000
  43. - default_lease_time|int >= 21600
  44. success_msg: "{{ success_msg_lease_time }}"
  45. fail_msg: "{{ fail_msg_lease_time }}"
  46. - name: Calculate max lease time
  47. set_fact:
  48. max_lease_time: "{{ default_lease_time|int + 10000 }}"
  49. - name: Validate infiniband base_vars are not empty
  50. assert:
  51. that:
  52. - ib_network_nic | length > 2
  53. - ib_network_dhcp_start_range | length > 6
  54. - ib_network_dhcp_end_range | length > 6
  55. success_msg: "{{ success_msg_ib }}"
  56. fail_msg: "{{ fail_msg_ib }}"
  57. register: ib_check
  58. when: ib_switch_support
  59. - name: Set facts to validate snmp support
  60. set_fact:
  61. snmp_enabled: false
  62. mngmnt_mapping_file: false
  63. host_mapping_file: false
  64. - name: Verify snmp_trap_destination IP address
  65. set_fact:
  66. snmp_enabled: true
  67. when: snmp_trap_destination | length > 1
  68. - name: Assert snmp trap destination address
  69. assert:
  70. that:
  71. - snmp_enabled
  72. - snmp_trap_destination | length > 7
  73. - snmp_trap_destination | ipv4
  74. success_msg: "{{ success_snmp_trap_dest }}"
  75. fail_msg: "{{ fail_snmp_trap_dest }}"
  76. when: snmp_enabled
  77. - name: Assert snmp community string
  78. assert:
  79. that:
  80. - snmp_enabled
  81. - snmp_community_name
  82. success_msg: "{{ success_snmp_comm_msg }}"
  83. fail_msg: "{{ fail_snmp_comm_msg }}"
  84. when: snmp_enabled
  85. - name: Check whether ansible config file exists
  86. stat:
  87. path: "{{ ansible_conf_file_path }}/ansible.cfg"
  88. register: ansible_conf_exists
  89. - name: Create the directory if it does not exist
  90. file:
  91. path: "{{ ansible_conf_file_path }}"
  92. state: directory
  93. mode: "{{ file_perm }}"
  94. when: not ansible_conf_exists.stat.exists
  95. changed_when: false
  96. - name: Create ansible config file if it does not exist
  97. copy:
  98. dest: '{{ ansible_conf_file_path }}/ansible.cfg'
  99. mode: "{{ file_perm }}"
  100. content: |
  101. [defaults]
  102. log_path = /var/log/omnia.log
  103. when: not ansible_conf_exists.stat.exists
  104. - name: Assert ethernet_switch_support
  105. assert:
  106. that:
  107. - ethernet_switch_support == true or ethernet_switch_support == false
  108. success_msg: "{{ ethernet_switch_support_success_msg }}"
  109. fail_msg: "{{ ethernet_switch_support_fail_msg }}"
  110. - name: Assert ib_switch_support
  111. assert:
  112. that:
  113. - ib_switch_support == true or ib_switch_support == false
  114. success_msg: "{{ ib_switch_support_success_msg }}"
  115. fail_msg: "{{ ib_switch_support_fail_msg }}"
  116. - name: Assert powervault_support
  117. assert:
  118. that:
  119. - powervault_support == true or powervault_support == false
  120. success_msg: "{{ powervault_support_success_msg }}"
  121. fail_msg: "{{ powervault_support_fail_msg }}"
  122. - name: Fetch the network interfaces in UP state in the system
  123. shell: set -o pipefail && ip a | awk '/state UP/{print $2}'
  124. register: nic_addr_up
  125. changed_when: false
  126. - name: Assert public nic
  127. assert:
  128. that:
  129. - public_nic in nic_addr_up.stdout
  130. success_msg: "{{ success_msg_public_nic }}"
  131. fail_msg: "{{ fail_msg_public_nic }}"
  132. - name: Fetch the system public IP
  133. set_fact:
  134. public_ip: "{{ lookup('vars','ansible_'+public_nic).ipv4.address }}"
  135. - name: Assert kubernetes pod network CIDR
  136. assert:
  137. that:
  138. - appliance_k8s_pod_net_cidr | ipv4
  139. - appliance_k8s_pod_net_cidr | length > 9
  140. - '"/" in appliance_k8s_pod_net_cidr '
  141. success_msg: "{{ success_msg_k8s_pod_network_cidr }}"
  142. fail_msg: "{{ fail_msg_k8s_pod_network_cidr }}"
  143. - name: Assert Organization in awx
  144. assert:
  145. that:
  146. - awx_organization | length >= min_username_length
  147. - awx_organization | length < max_length
  148. - '"-" not in awx_organization '
  149. - '"\\" not in awx_organization '
  150. - '"\"" not in awx_organization '
  151. - " \"'\" not in awx_organization "
  152. success_msg: "{{ success_awx_organization }}"
  153. fail_msg: "{{ fail_awx_organization }}"
  154. - name: Assert provisioning method
  155. assert:
  156. that:
  157. - provision_method == "pxe" or provision_method == "idrac"
  158. success_msg: "{{ success_provision_method }}"
  159. fail_msg: "{{ fail_provision_method }}"
  160. - name: Check timezone file
  161. command: grep -Fx "{{ timezone }}" {{ role_path }}/files/timezone.txt
  162. ignore_errors: yes
  163. register: timezone_out
  164. changed_when: false
  165. - name: Assert timezone
  166. assert:
  167. that: timezone in timezone_out.stdout
  168. success_msg: "{{ success_timezone_msg }}"
  169. fail_msg: "{{ fail_timezone_msg }}"
  170. register: timezone_check
  171. - name: Assert language for provisioning nodes
  172. fail:
  173. msg: "{{ fail_language }}"
  174. when: '"en-US" not in language'
  175. - name: Verify the iso_file_path
  176. stat:
  177. path: "{{ iso_file_path }}"
  178. register: result_path_iso_file
  179. - name : Assert iso_file_path
  180. fail:
  181. msg: "{{ invalid_iso_file_path }}"
  182. when: not result_path_iso_file.stat.exists
  183. - name: Fail when iso path valid but image not right
  184. fail:
  185. msg: "{{ invalid_iso_file_path }}"
  186. when:
  187. - result_path_iso_file.stat.exists
  188. - '".iso" not in iso_file_path'
  189. #### management_net_dhcp_start_end_range
  190. - name: Assert management network nic
  191. assert:
  192. that:
  193. - mngmnt_network_nic in nic_addr_up.stdout
  194. success_msg: "{{ success_msg_mngmnt_network_nic }}"
  195. fail_msg: "{{ fail_msg_mngmnt_network_nic }}"
  196. - name: Fetch the management network ip, netmask and subnet
  197. set_fact:
  198. mngmnt_network_ip: "{{ lookup('vars','ansible_'+mngmnt_network_nic).ipv4.address }}"
  199. mngmnt_network_netmask: "{{ lookup('vars','ansible_'+mngmnt_network_nic).ipv4.netmask }}"
  200. mngmnt_network_subnet: "{{ lookup('vars','ansible_'+mngmnt_network_nic).ipv4.network }}"
  201. - name: Check the subnet of management network dhcp start range
  202. shell: |
  203. IFS=. read -r i1 i2 i3 i4 <<< "{{ mngmnt_network_dhcp_start_range }}"
  204. IFS=. read -r m1 m2 m3 m4 <<< "{{ mngmnt_network_netmask }}"
  205. printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
  206. args:
  207. warn: no
  208. register: dhcp_start_mgmnt_result
  209. changed_when: false
  210. - name: Set the start dhcp subnet for management network
  211. set_fact:
  212. dhcp_start_mgmnt: "{{ dhcp_start_mgmnt_result.stdout }}"
  213. - name: Check the subnet of dhcp end range for management network
  214. shell: |
  215. IFS=. read -r i1 i2 i3 i4 <<< "{{ mngmnt_network_dhcp_end_range }}"
  216. IFS=. read -r m1 m2 m3 m4 <<< "{{ mngmnt_network_netmask }}"
  217. printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
  218. register: dhcp_end_mgmnt_result
  219. changed_when: false
  220. - name: Set the end dhcp subnet for management network
  221. set_fact:
  222. dhcp_end_mgmnt: "{{ dhcp_end_mgmnt_result.stdout }}"
  223. - name: Assert management_net_dhcp_start_range
  224. assert:
  225. that:
  226. - mngmnt_network_dhcp_start_range
  227. - mngmnt_network_dhcp_start_range | ipv4
  228. - mngmnt_network_dhcp_start_range != mngmnt_network_ip
  229. - mngmnt_network_dhcp_start_range != mngmnt_network_dhcp_end_range
  230. - dhcp_start_mgmnt == mngmnt_network_subnet
  231. - dhcp_start_mgmnt == dhcp_end_mgmnt
  232. success_msg: "{{ success_dhcp_range }} for management network"
  233. fail_msg: "{{ fail_dhcp_range }} for management network"
  234. - name: Assert management_net_dhcp_end_range
  235. assert:
  236. that:
  237. - mngmnt_network_dhcp_end_range
  238. - mngmnt_network_dhcp_end_range | ipv4
  239. - mngmnt_network_dhcp_end_range != mngmnt_network_ip
  240. - mngmnt_network_dhcp_start_range != mngmnt_network_dhcp_end_range
  241. - dhcp_end_mgmnt == mngmnt_network_subnet
  242. - dhcp_start_mgmnt == dhcp_end_mgmnt
  243. success_msg: "{{ success_dhcp_range }} for management network"
  244. fail_msg: "{{ fail_dhcp_range }} for management network"
  245. - name: Set the mapping file value for management network
  246. set_fact:
  247. mngmnt_mapping_file: true
  248. when: mngmnt_mapping_file_path | length > 0
  249. - name: Assert valid mngmnt_mapping_file_path
  250. stat:
  251. path: "{{ mngmnt_mapping_file_path }}"
  252. when: mngmnt_mapping_file
  253. register: result_mngmnt_mapping_file
  254. - name : Valid mngmnt_mapping_file_path
  255. fail:
  256. msg: "{{ invalid_mapping_file_path }} for management network"
  257. when: mngmnt_mapping_file and not result_mngmnt_mapping_file.stat.exists
  258. #########
  259. ###Host network####
  260. - name: Fetch the host network ip, netmask and subnet
  261. set_fact:
  262. hpc_ip: "{{ lookup('vars','ansible_'+host_network_nic).ipv4.address }}"
  263. netmask: "{{ lookup('vars','ansible_'+host_network_nic).ipv4.netmask }}"
  264. subnet: "{{ lookup('vars','ansible_'+host_network_nic).ipv4.network }}"
  265. - name: Check the subnet of host network dhcp start range
  266. shell: |
  267. IFS=. read -r i1 i2 i3 i4 <<< "{{ host_network_dhcp_start_range }}"
  268. IFS=. read -r m1 m2 m3 m4 <<< "{{ netmask }}"
  269. printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
  270. args:
  271. warn: no
  272. register: dhcp_start_host_result
  273. changed_when: false
  274. - name: Set the start dhcp subnet for host network
  275. set_fact:
  276. dhcp_start_host: "{{ dhcp_start_host_result.stdout }}"
  277. - name: Check the subnet of dhcp end range for host network
  278. shell: |
  279. IFS=. read -r i1 i2 i3 i4 <<< "{{ host_network_dhcp_end_range }}"
  280. IFS=. read -r m1 m2 m3 m4 <<< "{{ netmask }}"
  281. printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
  282. register: dhcp_end_host_result
  283. changed_when: false
  284. - name: Set the end dhcp subnet for host network
  285. set_fact:
  286. dhcp_end_host: "{{ dhcp_end_host_result.stdout }}"
  287. - name: Assert host_network_dhcp_start_range
  288. assert:
  289. that:
  290. - host_network_dhcp_start_range
  291. - host_network_dhcp_start_range | ipv4
  292. - host_network_dhcp_start_range != hpc_ip
  293. - host_network_dhcp_start_range != host_network_dhcp_end_range
  294. - dhcp_start_host == subnet
  295. - dhcp_start_host == dhcp_end_host
  296. success_msg: "{{ success_dhcp_range }} for host network"
  297. fail_msg: "{{ fail_dhcp_range }} for host network"
  298. - name: Assert host_network_dhcp_end_range
  299. assert:
  300. that:
  301. - host_network_dhcp_end_range
  302. - host_network_dhcp_end_range | ipv4
  303. - host_network_dhcp_end_range != hpc_ip
  304. - host_network_dhcp_start_range != host_network_dhcp_end_range
  305. - dhcp_end_host == subnet
  306. - dhcp_start_host == dhcp_end_host
  307. success_msg: "{{ success_dhcp_range }} for host network"
  308. fail_msg: "{{ fail_dhcp_range }} for host network"
  309. - name: Set the mapping file value for host network
  310. set_fact:
  311. host_mapping_file: true
  312. when: host_mapping_file_path | length > 0
  313. - name: Assert valid mapping_file_path
  314. stat:
  315. path: "{{ host_mapping_file_path }}"
  316. when: host_mapping_file
  317. register: result_host_mapping_file
  318. - name: Valid mapping_file_path
  319. fail:
  320. msg: "{{ invalid_mapping_file_path }} for host_network"
  321. when: host_mapping_file and not result_host_mapping_file.stat.exists
  322. - name: Verify different nics
  323. assert:
  324. that:
  325. - public_nic != mngmnt_network_nic
  326. - mngmnt_network_nic != host_network_nic
  327. - public_nic != host_network_nic
  328. success_msg: "{{ success_msg_different_nics }}"
  329. fail_msg: "{{ fail_msg_different_nics }}"
  330. ########
  331. - name: Fetch the infiniband network ip, netmask and subnet
  332. set_fact:
  333. ib_ip: "{{ lookup('vars','ansible_'+ib_network_nic).ipv4.address }}"
  334. ib_netmask: "{{ lookup('vars','ansible_'+ib_network_nic).ipv4.netmask }}"
  335. ib_subnet: "{{ lookup('vars','ansible_'+ib_network_nic).ipv4.network }}"
  336. when: ib_switch_support
  337. - name: Check the subnet of infiniband network dhcp start range
  338. shell: |
  339. IFS=. read -r i1 i2 i3 i4 <<< "{{ ib_network_dhcp_start_range }}"
  340. IFS=. read -r m1 m2 m3 m4 <<< "{{ ib_netmask }}"
  341. printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
  342. args:
  343. warn: no
  344. register: dhcp_start_ib_result
  345. when: ib_switch_support
  346. changed_when: false
  347. - name: Set the start dhcp subnet for infiniband network
  348. set_fact:
  349. dhcp_start_ib: "{{ dhcp_start_ib_result.stdout }}"
  350. when: ib_switch_support
  351. - name: Check the subnet of dhcp end range for infiniband network
  352. shell: |
  353. IFS=. read -r i1 i2 i3 i4 <<< "{{ ib_network_dhcp_end_range }}"
  354. IFS=. read -r m1 m2 m3 m4 <<< "{{ ib_netmask }}"
  355. printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
  356. register: dhcp_end_ib_result
  357. when: ib_switch_support
  358. changed_when: false
  359. - name: Set the end dhcp subnet for infiniband network
  360. set_fact:
  361. dhcp_end_ib: "{{ dhcp_end_ib_result.stdout }}"
  362. when: ib_switch_support
  363. - name: Assert infiniband_net_dhcp_start_range
  364. assert:
  365. that:
  366. - ib_network_dhcp_start_range
  367. - ib_network_dhcp_start_range | ipv4
  368. - ib_network_dhcp_start_range != ib_ip
  369. - ib_network_dhcp_start_range != ib_network_dhcp_end_range
  370. - dhcp_start_ib == ib_subnet
  371. - dhcp_start_ib == dhcp_end_ib
  372. success_msg: "{{ success_dhcp_range }} for infiniband network"
  373. fail_msg: "{{ fail_dhcp_range }} for infiniband network"
  374. when: ib_switch_support
  375. - name: Assert infiniband_net_dhcp_end_range
  376. assert:
  377. that:
  378. - ib_network_dhcp_end_range
  379. - ib_network_dhcp_end_range | ipv4
  380. - ib_network_dhcp_end_range != ib_ip
  381. - ib_network_dhcp_start_range != ib_network_dhcp_end_range
  382. - dhcp_end_ib == ib_subnet
  383. - dhcp_start_ib == dhcp_end_ib
  384. success_msg: "{{ success_dhcp_range }} for infiniband network"
  385. fail_msg: "{{ fail_dhcp_range }} for infiniband network"
  386. when: ib_switch_support
  387. - name: Verify different nics with infiniband nic
  388. assert:
  389. that:
  390. - public_nic != ib_network_nic
  391. - mngmnt_network_nic != ib_network_nic
  392. - ib_network_nic != host_network_nic
  393. success_msg: "{{ success_msg_different_nics_ib }}"
  394. fail_msg: "{{ fail_msg_different_nics_ib }}"
  395. when: ib_switch_support