password_config.yml 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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 input config file is encrypted
  16. command: cat {{ input_config_filename }}
  17. changed_when: false
  18. register: config_content
  19. - name: Decrpyt appliance_config.yml
  20. command: >-
  21. ansible-vault decrypt {{ input_config_filename }}
  22. --vault-password-file {{ vault_filename }}
  23. changed_when: false
  24. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  25. - name: Include variable file appliance_config.yml
  26. include_vars: "{{ input_config_filename }}"
  27. no_log: true
  28. - name: Validate input parameters are not empty
  29. fail:
  30. msg: "{{ input_config_failure_msg }}"
  31. register: input_config_check
  32. when:
  33. - provision_password | length < 1 or
  34. awx_password | length < 1 or
  35. hpc_nic | length < 1 or
  36. public_nic | length < 1 or
  37. iso_file_path | length < 1 or
  38. dhcp_start_ip_range | length < 1 or
  39. dhcp_end_ip_range | length < 1
  40. - name: Save input variables from file
  41. set_fact:
  42. cobbler_password: "{{ provision_password }}"
  43. admin_password: "{{ awx_password }}"
  44. nic: "{{ hpc_nic }}"
  45. internet_nic: "{{ public_nic }}"
  46. path_for_iso_file: "{{ iso_file_path }}"
  47. dhcp_start_ip: "{{ dhcp_start_ip_range | ipv4 }}"
  48. dhcp_end_ip: "{{ dhcp_end_ip_range | ipv4 }}"
  49. mapping_file: false
  50. path_for_mapping_file: "{{ mapping_file_path }}"
  51. no_log: true
  52. - name: Get the system hpc ip
  53. shell: "ifconfig {{ hpc_nic }} | grep 'inet' |cut -d: -f2 | awk '{ print $2}'"
  54. register: ip
  55. changed_when: false
  56. - name: Get the system public ip
  57. shell: "ifconfig {{ internet_nic }} | grep 'inet' |cut -d: -f2 | awk '{ print $2}'"
  58. register: internet_ip
  59. changed_when: false
  60. - name: Get the system netmask
  61. shell: "ifconfig {{ hpc_nic }} | grep 'inet' |cut -d: -f2 | awk '{ print $4}'"
  62. register: net
  63. changed_when: false
  64. - name: HPC nic IP
  65. set_fact:
  66. hpc_ip: "{{ ip.stdout }}"
  67. public_ip: "{{ internet_ip.stdout }}"
  68. - name: Netmask
  69. set_fact:
  70. netmask: "{{ net.stdout }}"
  71. - name: shell try
  72. shell: |
  73. IFS=. read -r i1 i2 i3 i4 <<< "{{ hpc_ip }}"
  74. IFS=. read -r m1 m2 m3 m4 <<< "{{ netmask }}"
  75. printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
  76. register: sub_result
  77. changed_when: false
  78. - name: Subnet
  79. set_fact:
  80. subnet: "{{ sub_result.stdout }}"
  81. - name: Assert provision_password
  82. assert:
  83. that:
  84. - cobbler_password | length > min_length | int - 1
  85. - cobbler_password | length < max_length | int + 1
  86. - '"-" not in cobbler_password '
  87. - '"\\" not in cobbler_password '
  88. - '"\"" not in cobbler_password '
  89. - " \"'\" not in cobbler_password "
  90. success_msg: "{{ success_msg_provision_password }}"
  91. fail_msg: "{{ fail_msg_provision_password }}"
  92. no_log: true
  93. register: cobbler_password_check
  94. - name: Assert awx_password
  95. assert:
  96. that:
  97. - admin_password | length > min_length | int - 1
  98. - admin_password | length < max_length | int + 1
  99. - '"-" not in admin_password '
  100. - '"\\" not in admin_password '
  101. - '"\"" not in admin_password '
  102. - " \"'\" not in admin_password "
  103. success_msg: "{{ success_msg_awx_password }}"
  104. fail_msg: "{{ fail_msg_awx_password }}"
  105. no_log: true
  106. register: awx_password_check
  107. - name: Assert hpc_ip
  108. assert:
  109. that:
  110. - hpc_ip | length > 7
  111. success_msg: "{{ success_hpc_ip }}"
  112. fail_msg: "{{ fail_hpc_ip }}"
  113. register: hpc_ip_check
  114. - name: Assert public_ip
  115. assert:
  116. that:
  117. - public_ip | length > 7
  118. success_msg: "{{ success_hpc_ip }}"
  119. fail_msg: "{{ fail_hpc_ip }}"
  120. register: public_ip_check
  121. - name: Assert hpc_nic
  122. assert:
  123. that:
  124. - nic | length > nic_min_length | int - 1
  125. - nic != internet_nic
  126. success_msg: "{{ success_msg_hpc_nic }}"
  127. fail_msg: "{{ fail_msg_hpc_nic }}"
  128. register: hpc_nic_check
  129. - name: Assert public_nic
  130. assert:
  131. that:
  132. - internet_nic | length > nic_min_length | int - 1
  133. - nic != internet_nic
  134. success_msg: "{{ success_msg_public_nic }}"
  135. fail_msg: "{{ fail_msg_public_nic }}"
  136. register: public_nic_check
  137. - name: Assert mapping_file_exists
  138. assert:
  139. that:
  140. - "( mapping_file == true ) or ( mapping_file == false )"
  141. success_msg: "{{ success_mapping_file }}"
  142. fail_msg: "{{ fail_mapping_file }}"
  143. - name: Set the mapping file value
  144. set_fact:
  145. mapping_file: true
  146. when: path_for_mapping_file != ""
  147. - name: Assert valid mapping_file_path
  148. stat:
  149. path: "{{ path_for_mapping_file }}"
  150. when: mapping_file == true
  151. register: result_path_mapping_file
  152. - name : Valid mapping_file_path
  153. fail:
  154. msg: "{{ invalid_mapping_file_path }}"
  155. when: ( mapping_file == true ) and ( result_path_mapping_file.stat.exists == false )
  156. - name: Assert valid iso_file_path
  157. stat:
  158. path: "{{ path_for_iso_file }}"
  159. register: result_path_iso_file
  160. - name : Incorrect iso_file_path
  161. fail:
  162. msg: "{{ invalid_iso_file_path }}"
  163. when: ( result_path_iso_file.stat.exists == false ) and ( ".iso" not in path_for_iso_file )
  164. - name: Fail when iso path valid but image not right
  165. fail:
  166. msg: "{{ invalid_iso_file_path }}"
  167. when: ( result_path_iso_file.stat.exists == true ) and ( ".iso" not in path_for_iso_file )
  168. - name: Check the subnet of dhcp start range
  169. shell: |
  170. IFS=. read -r i1 i2 i3 i4 <<< "{{ dhcp_start_ip }}"
  171. IFS=. read -r m1 m2 m3 m4 <<< "{{ netmask }}"
  172. printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
  173. args:
  174. warn: no
  175. register: dhcp_start_sub_result
  176. changed_when: false
  177. when: dhcp_start_ip != "false"
  178. - name: Set the start dhcp subnet
  179. set_fact:
  180. dhcp_start_sub: "{{ dhcp_start_sub_result.stdout }}"
  181. when: dhcp_start_ip != "false"
  182. - name: Check the subnet of dhcp end range
  183. shell: |
  184. IFS=. read -r i1 i2 i3 i4 <<< "{{ dhcp_end_ip }}"
  185. IFS=. read -r m1 m2 m3 m4 <<< "{{ netmask }}"
  186. printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
  187. register: dhcp_end_sub_result
  188. when: dhcp_end_ip != "false"
  189. changed_when: false
  190. - name: Set the end dhcp subnet
  191. set_fact:
  192. dhcp_end_sub: "{{ dhcp_end_sub_result.stdout }}"
  193. when: dhcp_end_ip != "false"
  194. - name: Assert dhcp_start_ip_range
  195. assert:
  196. that:
  197. - dhcp_start_ip != "false"
  198. - dhcp_start_ip != dhcp_end_ip
  199. - dhcp_start_sub == subnet
  200. - dhcp_start_sub == dhcp_end_sub
  201. success_msg: "{{ success_dhcp_range }}"
  202. fail_msg: "{{ fail_dhcp_range }}"
  203. register: dhcp_start_ip_check
  204. - name: Assert dhcp_end_ip_range
  205. assert:
  206. that:
  207. - dhcp_end_ip != "false"
  208. - dhcp_start_ip != dhcp_end_ip
  209. - dhcp_end_sub == subnet
  210. - dhcp_start_sub == dhcp_end_sub
  211. success_msg: "{{ success_dhcp_range }}"
  212. fail_msg: "{{ fail_dhcp_range }}"
  213. register: dhcp_end_ip_check
  214. - name: Create ansible vault key
  215. set_fact:
  216. vault_key: "{{ lookup('password', '/dev/null chars=ascii_letters') }}"
  217. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  218. - name: Save vault key
  219. copy:
  220. dest: "{{ vault_filename }}"
  221. content: |
  222. {{ vault_key }}
  223. owner: root
  224. force: yes
  225. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  226. - name: Encrypt input config file
  227. command: >-
  228. ansible-vault encrypt {{ input_config_filename }}
  229. --vault-password-file {{ vault_filename }}
  230. changed_when: false
  231. - name: Check if omnia_vault_key exists
  232. stat:
  233. path: "{{ role_path }}/../../../{{ config_vaultname }}"
  234. register: vault_key_result
  235. - name: Create ansible vault key if it does not exist
  236. set_fact:
  237. vault_key: "{{ lookup('password', '/dev/null chars=ascii_letters') }}"
  238. when: not vault_key_result.stat.exists
  239. - name: Save vault key
  240. copy:
  241. dest: "{{ role_path }}/../../../{{ config_vaultname }}"
  242. content: |
  243. {{ vault_key }}
  244. owner: root
  245. force: yes
  246. when: not vault_key_result.stat.exists
  247. - name: Check if omnia config file is encrypted
  248. command: cat {{ role_path }}/../../../{{ config_filename }}
  249. changed_when: false
  250. register: config_content
  251. no_log: True
  252. - name: Decrpyt omnia_config.yml
  253. command: >-
  254. ansible-vault decrypt {{ role_path }}/../../../{{ config_filename }}
  255. --vault-password-file {{ role_path }}/../../../{{ config_vaultname }}
  256. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  257. - name: Include variable file omnia_config.yml
  258. include_vars: "{{ role_path }}/../../../{{ config_filename }}"
  259. no_log: True
  260. - name: Validate input parameters are not empty
  261. fail:
  262. msg: "{{ input_config_failure_msg }}"
  263. register: input_config_check
  264. when:
  265. - mariadb_password | length < 1 or
  266. k8s_cni | length < 1
  267. - name: Assert mariadb_password
  268. assert:
  269. that:
  270. - mariadb_password | length > min_length | int - 1
  271. - mariadb_password | length < max_length | int + 1
  272. - '"-" not in mariadb_password '
  273. - '"\\" not in mariadb_password '
  274. - '"\"" not in mariadb_password '
  275. - " \"'\" not in mariadb_password "
  276. success_msg: "{{ success_msg_mariadb_password }}"
  277. fail_msg: "{{ fail_msg_mariadb_password }}"
  278. - name: Assert kubernetes cni
  279. assert:
  280. that: "('calico' in k8s_cni) or ('flannel' in k8s_cni)"
  281. success_msg: "{{ success_msg_k8s_cni }}"
  282. fail_msg: "{{ fail_msg_k8s_cni }}"
  283. - name: Save input variables from file
  284. set_fact:
  285. db_password: "{{ mariadb_password }}"
  286. k8s_cni: "{{ k8s_cni }}"
  287. no_log: True
  288. - name: Encrypt input config file
  289. command: >-
  290. ansible-vault encrypt {{ role_path }}/../../../{{ config_filename }}
  291. --vault-password-file {{ role_path }}/../../../{{ config_vaultname }}
  292. changed_when: false