verify_omnia_params.yml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 if omnia_vault_key exists
  16. stat:
  17. path: "{{ role_path }}/../../../{{ config_vaultname }}"
  18. register: vault_key_result
  19. tags: init
  20. - name: Create ansible vault key if it does not exist
  21. set_fact:
  22. vault_key: "{{ lookup('password', '/dev/null chars=ascii_letters') }}"
  23. when: not vault_key_result.stat.exists
  24. tags: init
  25. - name: Save vault key
  26. copy:
  27. dest: "{{ role_path }}/../../../{{ config_vaultname }}"
  28. content: |
  29. {{ vault_key }}
  30. owner: root
  31. force: yes
  32. mode: "{{ vault_file_perm }}"
  33. when: not vault_key_result.stat.exists
  34. tags: init
  35. - name: Check if omnia config file is encrypted
  36. command: cat {{ role_path }}/../../../{{ config_filename }}
  37. changed_when: false
  38. register: config_content
  39. no_log: True
  40. tags: init
  41. - name: Decrpyt omnia_config.yml
  42. command: >-
  43. ansible-vault decrypt {{ role_path }}/../../../{{ config_filename }}
  44. --vault-password-file {{ role_path }}/../../../{{ config_vaultname }}
  45. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  46. tags: init
  47. - name: Include variable file omnia_config.yml
  48. include_vars: "{{ role_path }}/../../../{{ config_filename }}"
  49. no_log: True
  50. tags: init
  51. - name: Validate input parameters are not empty
  52. fail:
  53. msg: "{{ input_omnia_failure_msg }}"
  54. register: input_config_check
  55. tags: [ validate, templates ]
  56. when:
  57. - mariadb_password | length < 1 or
  58. k8s_version | length < 1 or
  59. k8s_cni | length < 1 or
  60. domain_name | length < 1
  61. - name: Validate login node parameters when login_node_reqd is set to true
  62. fail:
  63. msg: "{{ omnia_input_config_failure_msg }}"
  64. tags: [ validate, templates ]
  65. when:
  66. - ( domain_name | length < 1 or
  67. realm_name | length < 1 or
  68. directory_manager_password | length < 1 or
  69. kerberos_admin_password | length < 1 ) and
  70. ( login_node_required and
  71. host_mapping_file and
  72. not enable_security_support)
  73. - name: Assert mariadb_password
  74. assert:
  75. that:
  76. - mariadb_password | length > min_length | int - 1
  77. - mariadb_password | length < max_length | int + 1
  78. - '"-" not in mariadb_password '
  79. - '"\\" not in mariadb_password '
  80. - '"\"" not in mariadb_password '
  81. - " \"'\" not in mariadb_password "
  82. success_msg: "{{ success_msg_mariadb_password }}"
  83. fail_msg: "{{ fail_msg_mariadb_password }}"
  84. tags: [ validate, templates ]
  85. - name: Assert kubernetes version
  86. assert:
  87. that: "('1.16.7' in k8s_version) or ('1.19.3' in k8s_version)"
  88. success_msg: "{{ success_msg_k8s_version }}"
  89. fail_msg: "{{ fail_msg_k8s_version }}"
  90. tags: [ validate, templates ]
  91. - name: Assert kubernetes cni
  92. assert:
  93. that: "('calico' in k8s_cni) or ('flannel' in k8s_cni)"
  94. success_msg: "{{ success_msg_k8s_cni }}"
  95. fail_msg: "{{ fail_msg_k8s_cni }}"
  96. tags: [ validate, templates ]
  97. - name: Save input variables from file
  98. set_fact:
  99. db_password: "{{ mariadb_password }}"
  100. k8s_version: "{{ k8s_version }}"
  101. k8s_cni: "{{ k8s_cni }}"
  102. docker_username: "{{ docker_username }}"
  103. docker_password: "{{ docker_password }}"
  104. no_log: True
  105. tags: init
  106. - name: Verify the value of login_node_required
  107. assert:
  108. that:
  109. - login_node_required == true or login_node_required == false
  110. success_msg: "{{ login_node_required_success_msg }}"
  111. fail_msg: "{{ login_node_required_fail_msg }}"
  112. tags: [ validate, templates ]
  113. - name: Verify the value of enable_secure_login_node
  114. assert:
  115. that:
  116. - enable_secure_login_node == true or enable_secure_login_node == false
  117. success_msg: "{{ secure_login_node_success_msg }}"
  118. fail_msg: "{{ secure_login_node_fail_msg }}"
  119. tags: [ validate, templates ]
  120. - name: Validate the domain name
  121. assert:
  122. that:
  123. - domain_name is regex("^(?!-)[A-Za-z0-9-]+([\\-\\.]{1}[a-z0-9]+)*\\.[A-Za-z]{2,}$")
  124. success_msg: "{{ domain_name_success_msg }}"
  125. fail_msg: "{{ domain_name_fail_msg }}"
  126. tags: [ validate, templates ]
  127. when:
  128. - host_mapping_file
  129. - login_node_required
  130. - not enable_security_support
  131. - name: Validate the realm name
  132. assert:
  133. that:
  134. - realm_name is regex("^(?!-)[A-Z0-9-]+([\\-\\.]{1}[a-z0-9]+)*\\.[A-Z]{2,}$")
  135. - '"." in realm_name'
  136. success_msg: "{{ realm_name_success_msg }}"
  137. fail_msg: "{{ realm_name_fail_msg }}"
  138. tags: [ validate, templates ]
  139. when:
  140. - host_mapping_file
  141. - login_node_required
  142. - not enable_security_support
  143. - name: Assert directory_manager_password
  144. assert:
  145. that:
  146. - directory_manager_password | length > min_length | int - 1
  147. - directory_manager_password | length < max_length | int + 1
  148. - '"-" not in directory_manager_password '
  149. - '"\\" not in directory_manager_password '
  150. - '"\"" not in directory_manager_password '
  151. - " \"'\" not in directory_manager_password "
  152. success_msg: "{{ success_msg_directory_manager_password }}"
  153. fail_msg: "{{ fail_msg_directory_manager_password }}"
  154. tags: [ validate, templates ]
  155. when:
  156. - host_mapping_file
  157. - login_node_required
  158. - not enable_security_support
  159. - name: Assert kerberos_admin_password
  160. assert:
  161. that:
  162. - kerberos_admin_password | length > min_length | int - 1
  163. - kerberos_admin_password | length < max_length | int + 1
  164. - '"-" not in kerberos_admin_password '
  165. - '"\\" not in kerberos_admin_password '
  166. - '"\"" not in kerberos_admin_password '
  167. - " \"'\" not in kerberos_admin_password "
  168. success_msg: "{{ success_msg_kerberos_admin_password }}"
  169. fail_msg: "{{ fail_msg_kerberos_admin_password }}"
  170. tags: [ validate, templates ]
  171. when:
  172. - host_mapping_file
  173. - login_node_required
  174. - not enable_security_support
  175. - name: Encrypt input config file
  176. command: >-
  177. ansible-vault encrypt {{ role_path }}/../../../{{ config_filename }}
  178. --vault-password-file {{ role_path }}/../../../{{ config_vaultname }}
  179. changed_when: false
  180. tags: init
  181. - name: Update omnia_config.yml permission
  182. file:
  183. path: "{{ role_path }}/../../../{{ config_filename }}"
  184. mode: "{{ vault_file_perm }}"
  185. tags: init