verify_login_inputs.yml 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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: Check login_vars file is encrypted
  16. command: cat {{ login_vars_filename }}
  17. changed_when: false
  18. register: config_content
  19. no_log: true
  20. tags: init
  21. - name: Decrpyt login_vars.yml
  22. command: >-
  23. ansible-vault decrypt {{ login_vars_filename }}
  24. --vault-password-file {{ vault_filename }}
  25. changed_when: false
  26. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  27. tags: init
  28. - name: Include variable file login_vars.yml
  29. include_vars: "{{ login_vars_filename }}"
  30. no_log: true
  31. tags: init
  32. - name: Validate input parameters are not empty
  33. fail:
  34. msg: "{{ login_input_config_failure_msg }}"
  35. register: input_config_check
  36. when:
  37. - provision_password | length < 1 or
  38. cobbler_password | length < 1 or
  39. idrac_username | length < 1 or
  40. idrac_password | length < 1
  41. tags: [ validate, pxe, idrac ]
  42. - name: Validate security parameters when enable_security_support is set to true
  43. fail:
  44. msg: "{{ login_input_config_failure_msg }} for ipa server installation"
  45. tags: [ validate, security ]
  46. when:
  47. - ( ms_directory_manager_password | length < 1 or
  48. ms_ipa_admin_password | length < 1 ) and
  49. enable_security_support
  50. - name: Assert provision credentials
  51. block:
  52. - name: Assert provision_password
  53. assert:
  54. that:
  55. - provision_password | length > min_length | int - 1
  56. - provision_password | length < max_length | int + 1
  57. - '"-" not in provision_password '
  58. - '"\\" not in provision_password '
  59. - '"\"" not in provision_password '
  60. - " \"'\" not in provision_password "
  61. no_log: true
  62. rescue:
  63. - name: Provision password validation check
  64. fail:
  65. msg: "{{ fail_msg_provision_password }}"
  66. tags: [ validate, pxe, idrac ]
  67. - name: Assert cobbler credentials
  68. block:
  69. - name: Assert cobbler_password
  70. assert:
  71. that:
  72. - cobbler_password | length > min_length | int - 1
  73. - cobbler_password | length < max_length | int + 1
  74. - '"-" not in cobbler_password '
  75. - '"\\" not in cobbler_password '
  76. - '"\"" not in cobbler_password '
  77. - " \"'\" not in cobbler_password "
  78. no_log: true
  79. rescue:
  80. - name: Cobbler password validation check
  81. fail:
  82. msg: "{{ fail_msg_cobbler_password }}"
  83. tags: [ validate, pxe ]
  84. - name: Assert idrac credentials
  85. block:
  86. - name: Assert idrac_username and idrac_password
  87. assert:
  88. that:
  89. - idrac_username | length >= min_username_length
  90. - idrac_username | length < max_length
  91. - '"-" not in idrac_username '
  92. - '"\\" not in idrac_username '
  93. - '"\"" not in idrac_username '
  94. - " \"'\" not in idrac_username "
  95. - idrac_password | length > min_username_length | int - 1
  96. - idrac_password | length < max_length | int + 1
  97. - '"-" not in idrac_password '
  98. - '"\\" not in idrac_password '
  99. - '"\"" not in idrac_password '
  100. - " \"'\" not in idrac_password "
  101. no_log: true
  102. rescue:
  103. - name: idrac credentials validation check
  104. fail:
  105. msg: "{{ fail_msg_idrac_credentials }}"
  106. tags: [ validate, idrac ]
  107. - name: Assert grafana credentials
  108. block:
  109. - name: Assert grafana_username and grafana_username
  110. assert:
  111. that:
  112. - grafana_username | length >= min_length_grafana
  113. - grafana_username | length <= max_length
  114. - '"-" not in grafana_username '
  115. - '"\\" not in grafana_username '
  116. - '"\"" not in grafana_username '
  117. - " \"'\" not in grafana_username "
  118. - grafana_password | length >= min_length_grafana
  119. - grafana_password | length <= max_length
  120. - not grafana_password == 'admin'
  121. - '"-" not in grafana_password '
  122. - '"\\" not in grafana_password '
  123. - '"\"" not in grafana_password '
  124. - " \"'\" not in grafana_password "
  125. no_log: true
  126. rescue:
  127. - name: grafana credentials validation check
  128. fail:
  129. msg: "{{ fail_msg_grafana_credentials }}"
  130. tags: [ validate, monitoring ]
  131. - name: Assert username and password for ethernet switches
  132. block:
  133. - name: Verify ethernet_switch_username and ethernet_switch_password are not empty
  134. assert:
  135. that:
  136. - ethernet_switch_username | length >= min_username_length
  137. - ethernet_switch_username | length < max_length
  138. - '"-" not in ethernet_switch_username '
  139. - '"\\" not in ethernet_switch_username '
  140. - '"\"" not in ethernet_switch_username '
  141. - " \"'\" not in ethernet_switch_username "
  142. - ethernet_switch_password | length > min_username_length | int - 1
  143. - ethernet_switch_password | length < max_length | int + 1
  144. - '"-" not in ethernet_switch_password '
  145. - '"\\" not in ethernet_switch_password '
  146. - '"\"" not in ethernet_switch_password '
  147. - " \"'\" not in ethernet_switch_password "
  148. no_log: true
  149. rescue:
  150. - name: ethernet switch credentials validation check
  151. fail:
  152. msg: "{{ fail_msg_ethernet_credentials }}"
  153. when: ethernet_switch_support
  154. tags: [ validate, network-device ]
  155. - name: Assert username and password for IB switches
  156. block:
  157. - name: Assert ib_username and ib_password
  158. assert:
  159. that:
  160. - ib_username | length >= min_username_length
  161. - ib_username | length < max_length
  162. - '"-" not in ib_username '
  163. - '"\\" not in ib_username '
  164. - '"\"" not in ib_username '
  165. - " \"'\" not in ib_username "
  166. - ib_password | length > min_username_length | int - 1
  167. - ib_password | length < max_length | int + 1
  168. - '"-" not in ib_password '
  169. - '"\\" not in ib_password '
  170. - '"\"" not in ib_password '
  171. - " \"'\" not in ib_password "
  172. no_log: true
  173. rescue:
  174. - name: IB switch credentials validation check
  175. fail:
  176. msg: "{{ fail_msg_ib_credentials }}"
  177. when: ib_switch_support
  178. tags: [ validate, network-ib ]
  179. - name: Assert username and password for powervault me4
  180. block:
  181. - name: Assert powervault_me4_username and powervault_me4_password
  182. assert:
  183. that:
  184. - powervault_me4_username | length >= min_username_length
  185. - powervault_me4_username | length < max_length
  186. - '"-" not in powervault_me4_username '
  187. - '"\\" not in powervault_me4_username '
  188. - '"\"" not in powervault_me4_username '
  189. - " \"'\" not in powervault_me4_username "
  190. - powervault_me4_password | length > min_length | int - 1
  191. - powervault_me4_password | length < max_length | int + 1
  192. - '"-" not in powervault_me4_password '
  193. - '"," not in powervault_me4_password '
  194. - '"." not in powervault_me4_password '
  195. - '"<" not in powervault_me4_password '
  196. - '"\\" not in powervault_me4_password '
  197. - '"\"" not in powervault_me4_password '
  198. - " \"'\" not in powervault_me4_password "
  199. - powervault_me4_password | regex_search('^(?=.*[a-z]).+$')
  200. - powervault_me4_password | regex_search('^(?=.*[A-Z]).+$')
  201. - powervault_me4_password | regex_search('^(?=.*\\d).+$')
  202. - powervault_me4_password | regex_search('^(?=.*[!#$%&()*+/:;=>?@^_`{} ~]).+$')
  203. no_log: true
  204. rescue:
  205. - name: Powervault me4 credentials validation check
  206. fail:
  207. msg: "{{ fail_msg_me4_credentials }}"
  208. when: powervault_support
  209. tags: [ validate, network-device ]
  210. - name: Assert ms_directory_manager_password
  211. assert:
  212. that:
  213. - ms_directory_manager_password | length > min_length | int - 1
  214. - ms_directory_manager_password | length < max_length | int + 1
  215. - '"-" not in ms_directory_manager_password '
  216. - '"\\" not in ms_directory_manager_password '
  217. - '"\"" not in ms_directory_manager_password '
  218. - " \"'\" not in ms_directory_manager_password "
  219. success_msg: "{{ success_msg_dir_manager_password }}"
  220. fail_msg: "{{ fail_msg_dir_manager_password }}"
  221. when: enable_security_support
  222. tags: [ validate, security ]
  223. - name: Assert ms_ipa_admin_password
  224. assert:
  225. that:
  226. - ms_ipa_admin_password | length > min_length | int - 1
  227. - ms_ipa_admin_password | length < max_length | int + 1
  228. - '"-" not in ms_ipa_admin_password '
  229. - '"\\" not in ms_ipa_admin_password '
  230. - '"\"" not in ms_ipa_admin_password '
  231. - " \"'\" not in ms_ipa_admin_password "
  232. success_msg: "{{ success_msg_ipa_admin_pwd }}"
  233. fail_msg: "{{ fail_msg_ipa_admin_pwd }}"
  234. when: enable_security_support
  235. tags: [ validate, security ]
  236. - name: Create ansible vault key
  237. set_fact:
  238. vault_key: "{{ lookup('password', '/dev/null chars=ascii_letters') }}"
  239. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  240. tags: init
  241. - name: Save vault key
  242. copy:
  243. dest: "{{ vault_filename }}"
  244. content: |
  245. {{ vault_key }}
  246. owner: root
  247. force: yes
  248. mode: "{{ vault_file_perm }}"
  249. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  250. tags: init
  251. - name: Encrypt input config file
  252. command: >-
  253. ansible-vault encrypt {{ login_vars_filename }}
  254. --vault-password-file {{ vault_filename }}
  255. changed_when: false
  256. tags: init
  257. - name: Update login_vars.yml permission
  258. file:
  259. path: "{{ login_vars_filename }}"
  260. mode: "{{ file_perm }}"
  261. tags: init