password_config.yml 10 KB

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