verify_omnia_params.yml 5.6 KB

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