fetch_password.yml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. # Copyright 2020 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: "('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: Assert kubernetes pod network CIDR
  86. assert:
  87. that:
  88. - k8s_pod_network_cidr | length > 9
  89. - '"/" in k8s_pod_network_cidr '
  90. success_msg: "{{ success_msg_k8s_pod_network_cidr }}"
  91. fail_msg: "{{ fail_msg_k8s_pod_network_cidr }}"
  92. - name: Save input variables from file
  93. set_fact:
  94. db_password: "{{ mariadb_password }}"
  95. k8s_version: "{{ k8s_version }}"
  96. k8s_cni: "{{ k8s_cni }}"
  97. k8s_pod_network_cidr: "{{ k8s_pod_network_cidr }}"
  98. docker_username: "{{ docker_username }}"
  99. docker_password: "{{ docker_password }}"
  100. ansible_conf_file_path: "{{ ansible_config_file_path }}"
  101. no_log: True
  102. - name: Check whether ansible config file exists
  103. stat:
  104. path: "{{ ansible_conf_file_path }}/ansible.cfg"
  105. register: ansible_conf_exists
  106. - name: Create the directory if it does not exist
  107. file:
  108. path: "{{ ansible_conf_file_path }}"
  109. state: directory
  110. mode: "{{ file_perm }}"
  111. when: not ansible_conf_exists.stat.exists
  112. - name: Create ansible config file if it does not exist
  113. copy:
  114. dest: "{{ ansible_conf_file_path }}/ansible.cfg"
  115. mode: "{{ file_perm }}"
  116. content: |
  117. [defaults]
  118. log_path = /var/log/omnia.log
  119. when: not ansible_conf_exists.stat.exists
  120. - name: Set omnia.log file
  121. replace:
  122. path: "{{ ansible_conf_file_path }}/ansible.cfg"
  123. regexp: '#log_path = /var/log/ansible.log'
  124. replace: 'log_path = /var/log/omnia.log'
  125. when: ansible_conf_exists.stat.exists
  126. - name: Verify the value of login_node_required
  127. assert:
  128. that:
  129. - login_node_required == true or login_node_required == false
  130. success_msg: "{{ login_node_required_success_msg }}"
  131. fail_msg: "{{ login_node_required_fail_msg }}"
  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,6}$")
  143. success_msg: "{{ domain_name_success_msg }}"
  144. fail_msg: "{{ domain_name_fail_msg }}"
  145. when: login_node_required
  146. - name: Validate the realm name
  147. assert:
  148. that:
  149. - realm_name is regex("^(?!-)[A-Z0-9-]+([\\-\\.]{1}[a-z0-9]+)*\\.[A-Z]{2,6}$")
  150. - '"." in realm_name'
  151. success_msg: "{{ realm_name_success_msg }}"
  152. fail_msg: "{{ realm_name_fail_msg }}"
  153. when: login_node_required
  154. - name: Assert directory_manager_password
  155. assert:
  156. that:
  157. - directory_manager_password | length > min_length | int - 1
  158. - directory_manager_password | length < max_length | int + 1
  159. - '"-" not in directory_manager_password '
  160. - '"\\" not in directory_manager_password '
  161. - '"\"" not in directory_manager_password '
  162. - " \"'\" not in directory_manager_password "
  163. success_msg: "{{ success_msg_directory_manager_password }}"
  164. fail_msg: "{{ fail_msg_directory_manager_password }}"
  165. when: login_node_required
  166. - name: Assert ipa_admin_password
  167. assert:
  168. that:
  169. - ipa_admin_password | length > min_length | int - 1
  170. - ipa_admin_password | length < max_length | int + 1
  171. - '"-" not in ipa_admin_password '
  172. - '"\\" not in ipa_admin_password '
  173. - '"\"" not in ipa_admin_password '
  174. - " \"'\" not in ipa_admin_password "
  175. success_msg: "{{ success_msg_ipa_admin_password }}"
  176. fail_msg: "{{ fail_msg_ipa_admin_password }}"
  177. when: login_node_required
  178. - name: Encrypt input config file
  179. command: >-
  180. ansible-vault encrypt {{ role_path }}/../../{{ config_filename }}
  181. --vault-password-file {{ role_path }}/../../{{ config_vaultname }}
  182. changed_when: false