fetch_omnia_inputs.yml 7.0 KB

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