fetch_password.yml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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: Validate login node parameters when login_node_reqd is set to true
  58. fail:
  59. msg: "{{ input_config_failure_msg }} for login_node"
  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. not enable_security_support
  67. - name: Assert mariadb_password
  68. assert:
  69. that:
  70. - mariadb_password | length > min_length | int - 1
  71. - mariadb_password | length < max_length | int + 1
  72. - '"-" not in mariadb_password '
  73. - '"\\" not in mariadb_password '
  74. - '"\"" not in mariadb_password '
  75. - " \"'\" not in mariadb_password "
  76. success_msg: "{{ success_msg_mariadb_password }}"
  77. fail_msg: "{{ fail_msg_mariadb_password }}"
  78. - name: Assert kubernetes version
  79. assert:
  80. that: "('1.16.7' in k8s_version) or ('1.19.3' in k8s_version)"
  81. success_msg: "{{ success_msg_k8s_version }}"
  82. fail_msg: "{{ fail_msg_k8s_version }}"
  83. - name: Assert kubernetes cni
  84. assert:
  85. that:
  86. - "('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: Assert kubernetes pod network CIDR
  90. assert:
  91. that:
  92. - k8s_pod_network_cidr | length > 9
  93. - '"/" in k8s_pod_network_cidr '
  94. success_msg: "{{ success_msg_k8s_pod_network_cidr }}"
  95. fail_msg: "{{ fail_msg_k8s_pod_network_cidr }}"
  96. - name: Save input variables from file
  97. set_fact:
  98. db_password: "{{ mariadb_password }}"
  99. k8s_version: "{{ k8s_version }}"
  100. k8s_cni: "{{ k8s_cni }}"
  101. k8s_pod_network_cidr: "{{ k8s_pod_network_cidr }}"
  102. docker_username: "{{ docker_username }}"
  103. docker_password: "{{ docker_password }}"
  104. ansible_conf_file_path: "{{ ansible_config_file_path }}"
  105. no_log: True
  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. - name: Login node to contain exactly 1 node
  113. assert:
  114. that:
  115. - "groups['login_node'] | length | int == 1"
  116. fail_msg: "{{ login_node_group_fail_msg }}"
  117. success_msg: "{{ login_node_group_success_msg }}"
  118. when: login_node_required
  119. - name: Validate the domain name
  120. assert:
  121. that:
  122. - domain_name is regex("^(?!-)[A-Za-z0-9-]+([\\-\\.]{1}[a-z0-9]+)*\\.[A-Za-z]{2,}$")
  123. success_msg: "{{ domain_name_success_msg }}"
  124. fail_msg: "{{ domain_name_fail_msg }}"
  125. when:
  126. - login_node_required
  127. - not enable_security_support
  128. - name: Validate the realm name
  129. assert:
  130. that:
  131. - realm_name is regex("^(?!-)[A-Z0-9-]+([\\-\\.]{1}[a-z0-9]+)*\\.[A-Z]{2,}$")
  132. - '"." in realm_name'
  133. success_msg: "{{ realm_name_success_msg }}"
  134. fail_msg: "{{ realm_name_fail_msg }}"
  135. when:
  136. - login_node_required
  137. - not enable_security_support
  138. - name: Assert directory_manager_password
  139. assert:
  140. that:
  141. - directory_manager_password | length > min_length | int - 1
  142. - directory_manager_password | length < max_length | int + 1
  143. - '"-" not in directory_manager_password '
  144. - '"\\" not in directory_manager_password '
  145. - '"\"" not in directory_manager_password '
  146. - " \"'\" not in directory_manager_password "
  147. success_msg: "{{ success_msg_directory_manager_password }}"
  148. fail_msg: "{{ fail_msg_directory_manager_password }}"
  149. when:
  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. when:
  164. - login_node_required
  165. - not enable_security_support
  166. - name: Encrypt input config file
  167. command: >-
  168. ansible-vault encrypt {{ role_path }}/../../{{ config_filename }}
  169. --vault-password-file {{ role_path }}/../../{{ config_vaultname }}
  170. changed_when: false