verify_omnia_params.yml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. ipa_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: Validate the domain name
  114. assert:
  115. that:
  116. - domain_name is regex("^(?!-)[A-Za-z0-9-]+([\\-\\.]{1}[a-z0-9]+)*\\.[A-Za-z]{2,}$")
  117. success_msg: "{{ domain_name_success_msg }}"
  118. fail_msg: "{{ domain_name_fail_msg }}"
  119. tags: [ validate, templates ]
  120. when:
  121. - host_mapping_file
  122. - login_node_required
  123. - not enable_security_support
  124. - name: Validate the realm name
  125. assert:
  126. that:
  127. - realm_name is regex("^(?!-)[A-Z0-9-]+([\\-\\.]{1}[a-z0-9]+)*\\.[A-Z]{2,}$")
  128. - '"." in realm_name'
  129. success_msg: "{{ realm_name_success_msg }}"
  130. fail_msg: "{{ realm_name_fail_msg }}"
  131. tags: [ validate, templates ]
  132. when:
  133. - host_mapping_file
  134. - login_node_required
  135. - not enable_security_support
  136. - name: Assert directory_manager_password
  137. assert:
  138. that:
  139. - directory_manager_password | length > min_length | int - 1
  140. - directory_manager_password | length < max_length | int + 1
  141. - '"-" not in directory_manager_password '
  142. - '"\\" not in directory_manager_password '
  143. - '"\"" not in directory_manager_password '
  144. - " \"'\" not in directory_manager_password "
  145. success_msg: "{{ success_msg_directory_manager_password }}"
  146. fail_msg: "{{ fail_msg_directory_manager_password }}"
  147. tags: [ validate, templates ]
  148. when:
  149. - host_mapping_file
  150. - login_node_required
  151. - not enable_security_support
  152. - name: Assert ipa_admin_password
  153. assert:
  154. that:
  155. - ipa_admin_password | length > min_length | int - 1
  156. - ipa_admin_password | length < max_length | int + 1
  157. - '"-" not in ipa_admin_password '
  158. - '"\\" not in ipa_admin_password '
  159. - '"\"" not in ipa_admin_password '
  160. - " \"'\" not in ipa_admin_password "
  161. success_msg: "{{ success_msg_ipa_admin_password }}"
  162. fail_msg: "{{ fail_msg_ipa_admin_password }}"
  163. tags: [ validate, templates ]
  164. when:
  165. - host_mapping_file
  166. - login_node_required
  167. - not enable_security_support
  168. - name: Encrypt input config file
  169. command: >-
  170. ansible-vault encrypt {{ role_path }}/../../../{{ config_filename }}
  171. --vault-password-file {{ role_path }}/../../../{{ config_vaultname }}
  172. changed_when: false
  173. tags: init
  174. - name: Update omnia_config.yml permission
  175. file:
  176. path: "{{ role_path }}/../../../{{ config_filename }}"
  177. mode: "{{ vault_file_perm }}"
  178. tags: init