verify_omnia_params.yml 5.9 KB

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