password_config.yml 11 KB

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