password_config.yml 11 KB

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