fetch_password.yml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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: '0600'
  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_config_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. k8s_pod_network_cidr | length < 1 or
  54. ansible_config_file_path | length < 1
  55. - name: Validate login node parameters when login_node_reqd is set to true
  56. fail:
  57. msg: "{{ input_config_failure_msg }} for login_node"
  58. when:
  59. - ( domain_name | length < 1 or
  60. realm_name | length < 1 or
  61. directory_manager_password | length < 1 or
  62. ipa_admin_password | length < 1 ) and
  63. login_node_required
  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:
  83. - "('calico' in k8s_cni) or ('flannel' in k8s_cni)"
  84. success_msg: "{{ success_msg_k8s_cni }}"
  85. fail_msg: "{{ fail_msg_k8s_cni }}"
  86. - name: Assert kubernetes pod network CIDR
  87. assert:
  88. that:
  89. - k8s_pod_network_cidr | length > 9
  90. - '"/" in k8s_pod_network_cidr '
  91. success_msg: "{{ success_msg_k8s_pod_network_cidr }}"
  92. fail_msg: "{{ fail_msg_k8s_pod_network_cidr }}"
  93. - name: Save input variables from file
  94. set_fact:
  95. db_password: "{{ mariadb_password }}"
  96. k8s_version: "{{ k8s_version }}"
  97. k8s_cni: "{{ k8s_cni }}"
  98. k8s_pod_network_cidr: "{{ k8s_pod_network_cidr }}"
  99. docker_username: "{{ docker_username }}"
  100. docker_password: "{{ docker_password }}"
  101. ansible_conf_file_path: "{{ ansible_config_file_path }}"
  102. no_log: True
  103. - name: Verify the value of login_node_required
  104. assert:
  105. that:
  106. - login_node_required == true or login_node_required == false
  107. success_msg: "{{ login_node_required_success_msg }}"
  108. fail_msg: "{{ login_node_required_fail_msg }}"
  109. - name: Login node to contain exactly 1 node
  110. assert:
  111. that:
  112. - "groups['login_node'] | length | int == 1"
  113. fail_msg: "{{ login_node_group_fail_msg }}"
  114. success_msg: "{{ login_node_group_success_msg }}"
  115. when: login_node_required
  116. - name: Validate the domain name
  117. assert:
  118. that:
  119. - domain_name is regex("^(?!-)[A-Za-z0-9-]+([\\-\\.]{1}[a-z0-9]+)*\\.[A-Za-z]{2,}$")
  120. success_msg: "{{ domain_name_success_msg }}"
  121. fail_msg: "{{ domain_name_fail_msg }}"
  122. when: login_node_required
  123. - name: Validate the realm name
  124. assert:
  125. that:
  126. - realm_name is regex("^(?!-)[A-Z0-9-]+([\\-\\.]{1}[a-z0-9]+)*\\.[A-Z]{2,}$")
  127. - '"." in realm_name'
  128. success_msg: "{{ realm_name_success_msg }}"
  129. fail_msg: "{{ realm_name_fail_msg }}"
  130. when: login_node_required
  131. - name: Assert directory_manager_password
  132. assert:
  133. that:
  134. - directory_manager_password | length > min_length | int - 1
  135. - directory_manager_password | length < max_length | int + 1
  136. - '"-" not in directory_manager_password '
  137. - '"\\" not in directory_manager_password '
  138. - '"\"" not in directory_manager_password '
  139. - " \"'\" not in directory_manager_password "
  140. success_msg: "{{ success_msg_directory_manager_password }}"
  141. fail_msg: "{{ fail_msg_directory_manager_password }}"
  142. when: login_node_required
  143. - name: Assert ipa_admin_password
  144. assert:
  145. that:
  146. - ipa_admin_password | length > min_length | int - 1
  147. - ipa_admin_password | length < max_length | int + 1
  148. - '"-" not in ipa_admin_password '
  149. - '"\\" not in ipa_admin_password '
  150. - '"\"" not in ipa_admin_password '
  151. - " \"'\" not in ipa_admin_password "
  152. success_msg: "{{ success_msg_ipa_admin_password }}"
  153. fail_msg: "{{ fail_msg_ipa_admin_password }}"
  154. when: login_node_required
  155. - name: Encrypt input config file
  156. command: >-
  157. ansible-vault encrypt {{ role_path }}/../../{{ config_filename }}
  158. --vault-password-file {{ role_path }}/../../{{ config_vaultname }}
  159. changed_when: false