validate_nic_vars.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. - name: Fetch the network interfaces in UP state in the system
  16. shell: set -o pipefail && ip a | awk '/state UP/{print $2}'
  17. register: nic_addr_up
  18. changed_when: false
  19. tags: init
  20. ### public network
  21. - name: Assert public nic
  22. assert:
  23. that:
  24. - public_nic in nic_addr_up.stdout
  25. success_msg: "{{ success_msg_public_nic }}"
  26. fail_msg: "{{ fail_msg_public_nic }}"
  27. tags: [ validate, init ]
  28. - name: Fetch the system public IP
  29. set_fact:
  30. public_ip: "{{ lookup('vars','ansible_'+public_nic).ipv4.address }}"
  31. tags: init
  32. ### management network
  33. - block:
  34. - name: Assert management network nic
  35. assert:
  36. that:
  37. - mngmnt_network_nic in nic_addr_up.stdout
  38. success_msg: "{{ success_msg_mngmnt_network_nic }}"
  39. fail_msg: "{{ fail_msg_mngmnt_network_nic }}"
  40. tags: [ validate, network-device ]
  41. - name: Fetch the management network ip, netmask and subnet
  42. set_fact:
  43. mngmnt_network_ip: "{{ lookup('vars','ansible_'+mngmnt_network_nic).ipv4.address }}"
  44. mngmnt_network_netmask: "{{ lookup('vars','ansible_'+mngmnt_network_nic).ipv4.netmask }}"
  45. mngmnt_network_subnet: "{{ lookup('vars','ansible_'+mngmnt_network_nic).ipv4.network }}"
  46. tags: init
  47. - name: Check the subnet of management network dhcp start range
  48. shell: |
  49. IFS=. read -r i1 i2 i3 i4 <<< "{{ mngmnt_network_dhcp_start_range }}"
  50. IFS=. read -r m1 m2 m3 m4 <<< "{{ mngmnt_network_netmask }}"
  51. printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
  52. args:
  53. warn: no
  54. register: dhcp_start_mgmnt_result
  55. changed_when: false
  56. tags: init
  57. - name: Set the start dhcp subnet for management network
  58. set_fact:
  59. dhcp_start_mgmnt: "{{ dhcp_start_mgmnt_result.stdout }}"
  60. tags: init
  61. - name: Check the subnet of dhcp end range for management network
  62. shell: |
  63. IFS=. read -r i1 i2 i3 i4 <<< "{{ mngmnt_network_dhcp_end_range }}"
  64. IFS=. read -r m1 m2 m3 m4 <<< "{{ mngmnt_network_netmask }}"
  65. printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
  66. register: dhcp_end_mgmnt_result
  67. changed_when: false
  68. tags: init
  69. - name: Set the end dhcp subnet for management network
  70. set_fact:
  71. dhcp_end_mgmnt: "{{ dhcp_end_mgmnt_result.stdout }}"
  72. tags: init
  73. - name: Assert management_net_dhcp_start_range
  74. assert:
  75. that:
  76. - mngmnt_network_dhcp_start_range | length > 1
  77. - mngmnt_network_dhcp_start_range | ipv4
  78. - mngmnt_network_dhcp_start_range != mngmnt_network_ip
  79. - mngmnt_network_dhcp_start_range != mngmnt_network_dhcp_end_range
  80. - dhcp_start_mgmnt == mngmnt_network_subnet
  81. - dhcp_start_mgmnt == dhcp_end_mgmnt
  82. success_msg: "{{ success_dhcp_range }} for management network"
  83. fail_msg: "{{ fail_dhcp_range }} for management network"
  84. tags: [ validate, network-device ]
  85. - name: Assert management_net_dhcp_end_range
  86. assert:
  87. that:
  88. - mngmnt_network_dhcp_end_range | length > 1
  89. - mngmnt_network_dhcp_end_range | ipv4
  90. - mngmnt_network_dhcp_end_range != mngmnt_network_ip
  91. - mngmnt_network_dhcp_start_range != mngmnt_network_dhcp_end_range
  92. - dhcp_end_mgmnt == mngmnt_network_subnet
  93. - dhcp_start_mgmnt == dhcp_end_mgmnt
  94. success_msg: "{{ success_dhcp_range }} for management network"
  95. fail_msg: "{{ fail_dhcp_range }} for management network"
  96. tags: [ validate, network-device ]
  97. - name: Set the mapping file value for management network
  98. set_fact:
  99. mngmnt_mapping_file: true
  100. when: mngmnt_mapping_file_path | length > 0
  101. tags: init
  102. - name: Assert valid mngmnt_mapping_file_path
  103. stat:
  104. path: "{{ mngmnt_mapping_file_path }}"
  105. when: mngmnt_mapping_file
  106. register: result_mngmnt_mapping_file
  107. tags: init
  108. - name : Valid mngmnt_mapping_file_path
  109. fail:
  110. msg: "{{ invalid_mapping_file_path }} for management network"
  111. when: mngmnt_mapping_file and not result_mngmnt_mapping_file.stat.exists
  112. tags: init
  113. when: device_config_support
  114. ### host network
  115. - name: Fetch the host network ip, netmask and subnet
  116. set_fact:
  117. hpc_ip: "{{ lookup('vars','ansible_'+host_network_nic).ipv4.address }}"
  118. netmask: "{{ lookup('vars','ansible_'+host_network_nic).ipv4.netmask }}"
  119. subnet: "{{ lookup('vars','ansible_'+host_network_nic).ipv4.network }}"
  120. tags: init
  121. - name: Check the subnet of host network dhcp start range
  122. shell: |
  123. IFS=. read -r i1 i2 i3 i4 <<< "{{ host_network_dhcp_start_range }}"
  124. IFS=. read -r m1 m2 m3 m4 <<< "{{ netmask }}"
  125. printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
  126. args:
  127. warn: no
  128. register: dhcp_start_host_result
  129. changed_when: false
  130. tags: init
  131. - name: Set the start dhcp subnet for host network
  132. set_fact:
  133. dhcp_start_host: "{{ dhcp_start_host_result.stdout }}"
  134. tags: init
  135. - name: Check the subnet of dhcp end range for host network
  136. shell: |
  137. IFS=. read -r i1 i2 i3 i4 <<< "{{ host_network_dhcp_end_range }}"
  138. IFS=. read -r m1 m2 m3 m4 <<< "{{ netmask }}"
  139. printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
  140. register: dhcp_end_host_result
  141. changed_when: false
  142. tags: init
  143. - name: Set the end dhcp subnet for host network
  144. set_fact:
  145. dhcp_end_host: "{{ dhcp_end_host_result.stdout }}"
  146. tags: init
  147. - name: Assert host_network_dhcp_start_range
  148. assert:
  149. that:
  150. - host_network_dhcp_start_range | length > 1
  151. - host_network_dhcp_start_range | ipv4
  152. - host_network_dhcp_start_range != hpc_ip
  153. - host_network_dhcp_start_range != host_network_dhcp_end_range
  154. - dhcp_start_host == subnet
  155. - dhcp_start_host == dhcp_end_host
  156. success_msg: "{{ success_dhcp_range }} for host network"
  157. fail_msg: "{{ fail_dhcp_range }} for host network"
  158. tags: [ validate, pxe ]
  159. - name: Assert host_network_dhcp_end_range
  160. assert:
  161. that:
  162. - host_network_dhcp_end_range | length > 1
  163. - host_network_dhcp_end_range | ipv4
  164. - host_network_dhcp_end_range != hpc_ip
  165. - host_network_dhcp_start_range != host_network_dhcp_end_range
  166. - dhcp_end_host == subnet
  167. - dhcp_start_host == dhcp_end_host
  168. success_msg: "{{ success_dhcp_range }} for host network"
  169. fail_msg: "{{ fail_dhcp_range }} for host network"
  170. tags: [ validate, pxe ]
  171. - name: Set the mapping file value for host network
  172. set_fact:
  173. host_mapping_file: true
  174. when: host_mapping_file_path | length > 0
  175. tags: init
  176. - name: Assert valid mapping_file_path
  177. stat:
  178. path: "{{ host_mapping_file_path }}"
  179. when: host_mapping_file
  180. register: result_host_mapping_file
  181. tags: init
  182. - name: Valid mapping_file_path
  183. fail:
  184. msg: "{{ invalid_mapping_file_path }} for host_network"
  185. when: host_mapping_file and not result_host_mapping_file.stat.exists
  186. tags: init
  187. - name: Verify different nics
  188. assert:
  189. that:
  190. - public_nic != mngmnt_network_nic
  191. - mngmnt_network_nic != host_network_nic
  192. - public_nic != host_network_nic
  193. success_msg: "{{ success_msg_different_nics }}"
  194. fail_msg: "{{ fail_msg_different_nics }}"
  195. when: device_config_support
  196. tags: [ validate, pxe, network-device ]
  197. - name: Verify different nics
  198. assert:
  199. that:
  200. - public_nic != host_network_nic
  201. success_msg: "{{ success_msg_different_nics }}"
  202. fail_msg: "{{ fail_msg_different_nics }}"
  203. tags: [ validate, pxe ]
  204. ### ib network
  205. - block:
  206. - name: Fetch the infiniband network ip, netmask and subnet
  207. set_fact:
  208. ib_ip: "{{ lookup('vars','ansible_'+ib_network_nic).ipv4.address }}"
  209. ib_netmask: "{{ lookup('vars','ansible_'+ib_network_nic).ipv4.netmask }}"
  210. ib_subnet: "{{ lookup('vars','ansible_'+ib_network_nic).ipv4.network }}"
  211. tags: init
  212. - name: Check the subnet of infiniband network dhcp start range
  213. shell: |
  214. IFS=. read -r i1 i2 i3 i4 <<< "{{ ib_network_dhcp_start_range }}"
  215. IFS=. read -r m1 m2 m3 m4 <<< "{{ ib_netmask }}"
  216. printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
  217. args:
  218. warn: no
  219. register: dhcp_start_ib_result
  220. changed_when: false
  221. tags: init
  222. - name: Set the start dhcp subnet for infiniband network
  223. set_fact:
  224. dhcp_start_ib: "{{ dhcp_start_ib_result.stdout }}"
  225. tags: init
  226. - name: Check the subnet of dhcp end range for infiniband network
  227. shell: |
  228. IFS=. read -r i1 i2 i3 i4 <<< "{{ ib_network_dhcp_end_range }}"
  229. IFS=. read -r m1 m2 m3 m4 <<< "{{ ib_netmask }}"
  230. printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
  231. register: dhcp_end_ib_result
  232. changed_when: false
  233. tags: init
  234. - name: Set the end dhcp subnet for infiniband network
  235. set_fact:
  236. dhcp_end_ib: "{{ dhcp_end_ib_result.stdout }}"
  237. tags: init
  238. - name: Assert infiniband_net_dhcp_start_range
  239. assert:
  240. that:
  241. - ib_network_dhcp_start_range | length > 1
  242. - ib_network_dhcp_start_range | ipv4
  243. - ib_network_dhcp_start_range != ib_ip
  244. - ib_network_dhcp_start_range != ib_network_dhcp_end_range
  245. - dhcp_start_ib == ib_subnet
  246. - dhcp_start_ib == dhcp_end_ib
  247. success_msg: "{{ success_dhcp_range }} for infiniband network"
  248. fail_msg: "{{ fail_dhcp_range }} for infiniband network"
  249. tags: [ validate, network-ib ]
  250. - name: Assert infiniband_net_dhcp_end_range
  251. assert:
  252. that:
  253. - ib_network_dhcp_end_range | length > 1
  254. - ib_network_dhcp_end_range | ipv4
  255. - ib_network_dhcp_end_range != ib_ip
  256. - ib_network_dhcp_start_range != ib_network_dhcp_end_range
  257. - dhcp_end_ib == ib_subnet
  258. - dhcp_start_ib == dhcp_end_ib
  259. success_msg: "{{ success_dhcp_range }} for infiniband network"
  260. fail_msg: "{{ fail_dhcp_range }} for infiniband network"
  261. tags: [ validate, network-ib ]
  262. - name: Verify different nics with infiniband nic
  263. assert:
  264. that:
  265. - public_nic != ib_network_nic
  266. - mngmnt_network_nic != ib_network_nic
  267. - ib_network_nic != host_network_nic
  268. success_msg: "{{ success_msg_different_nics_ib }}"
  269. fail_msg: "{{ fail_msg_different_nics_ib }}"
  270. tags: [ validate, pxe, network-ib, network-device ]
  271. when: ib_switch_support