password_config.yml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. S
  20. - name: Decrpyt appliance_config.yml
  21. command: >-
  22. ansible-vault decrypt {{ input_config_filename }}
  23. --vault-password-file {{ vault_filename }}
  24. changed_when: false
  25. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  26. - name: Include variable file appliance_config.yml
  27. include_vars: "{{ input_config_filename }}"
  28. no_log: true
  29. - name: Validate input parameters are not empty
  30. fail:
  31. msg: "{{ input_config_failure_msg }}"
  32. register: input_config_check
  33. when:
  34. - provision_password | length < 1 or
  35. awx_password | length < 1 or
  36. hpc_nic | length < 1 or
  37. public_nic | 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. dhcp_start_ip: "{{ dhcp_start_ip_range | ipv4 }}"
  47. dhcp_end_ip: "{{ dhcp_end_ip_range | ipv4 }}"
  48. mapping_file: "{{ mapping_file_exists }}"
  49. no_log: true
  50. - name: Get the system hpc ip
  51. shell: "ifconfig {{ hpc_nic }} | grep 'inet' |cut -d: -f2 | awk '{ print $2}'"
  52. register: ip
  53. changed_when: false
  54. - name: Get the system public ip
  55. shell: "ifconfig {{ internet_nic }} | grep 'inet' |cut -d: -f2 | awk '{ print $2}'"
  56. register: internet_ip
  57. changed_when: false
  58. - name: Get the system netmask
  59. shell: "ifconfig {{ hpc_nic }} | grep 'inet' |cut -d: -f2 | awk '{ print $4}'"
  60. register: net
  61. changed_when: false
  62. - name: HPC nic IP
  63. set_fact:
  64. hpc_ip: "{{ ip.stdout }}"
  65. public_ip: "{{ internet_ip.stdout }}"
  66. - name: Netmask
  67. set_fact:
  68. netmask: "{{ net.stdout }}"
  69. - name: shell try
  70. shell: |
  71. IFS=. read -r i1 i2 i3 i4 <<< "{{ hpc_ip }}"
  72. IFS=. read -r m1 m2 m3 m4 <<< "{{ netmask }}"
  73. printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
  74. register: sub_result
  75. changed_when: false
  76. - name: Subnet
  77. set_fact:
  78. subnet: "{{ sub_result.stdout }}"
  79. - name: Assert provision_password
  80. assert:
  81. that:
  82. - cobbler_password | length > min_length | int - 1
  83. - cobbler_password | length < max_length | int + 1
  84. - '"-" not in cobbler_password '
  85. - '"\\" not in cobbler_password '
  86. - '"\"" not in cobbler_password '
  87. - " \"'\" not in cobbler_password "
  88. success_msg: "{{ success_msg_provision_password }}"
  89. fail_msg: "{{ fail_msg_provision_password }}"
  90. no_log: true
  91. register: cobbler_password_check
  92. - name: Assert awx_password
  93. assert:
  94. that:
  95. - admin_password | length > min_length | int - 1
  96. - admin_password | length < max_length | int + 1
  97. - '"-" not in admin_password '
  98. - '"\\" not in admin_password '
  99. - '"\"" not in admin_password '
  100. - " \"'\" not in admin_password "
  101. success_msg: "{{ success_msg_awx_password }}"
  102. fail_msg: "{{ fail_msg_awx_password }}"
  103. no_log: true
  104. register: awx_password_check
  105. - name: Assert hpc_ip
  106. assert:
  107. that:
  108. - hpc_ip | length > 7
  109. success_msg: "{{ success_hpc_ip }}"
  110. fail_msg: "{{ fail_hpc_ip }}"
  111. register: hpc_ip_check
  112. - name: Assert public_ip
  113. assert:
  114. that:
  115. - public_ip | length > 7
  116. success_msg: "{{ success_hpc_ip }}"
  117. fail_msg: "{{ fail_hpc_ip }}"
  118. register: public_ip_check
  119. - name: Assert hpc_nic
  120. assert:
  121. that:
  122. - nic | length > nic_min_length | int - 1
  123. - nic != internet_nic
  124. success_msg: "{{ success_msg_hpc_nic }}"
  125. fail_msg: "{{ fail_msg_hpc_nic }}"
  126. register: hpc_nic_check
  127. - name: Assert public_nic
  128. assert:
  129. that:
  130. - internet_nic | length > nic_min_length | int - 1
  131. - nic != internet_nic
  132. success_msg: "{{ success_msg_public_nic }}"
  133. fail_msg: "{{ fail_msg_public_nic }}"
  134. register: public_nic_check
  135. - name: Assert mapping_file_exists
  136. assert:
  137. that:
  138. - "( mapping_file == true) or ( mapping_file == false)"
  139. success_msg: "{{ success_mapping_file }}"
  140. fail_msg: "{{ fail_mapping_file }}"
  141. register: mapping_file_check
  142. - name: Check the subnet of dhcp start range
  143. shell: |
  144. IFS=. read -r i1 i2 i3 i4 <<< "{{ dhcp_start_ip }}"
  145. IFS=. read -r m1 m2 m3 m4 <<< "{{ netmask }}"
  146. printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
  147. args:
  148. warn: no
  149. register: dhcp_start_sub_result
  150. changed_when: false
  151. when: dhcp_start_ip != "false"
  152. - name: Set the start dhcp subnet
  153. set_fact:
  154. dhcp_start_sub: "{{ dhcp_start_sub_result.stdout }}"
  155. when: dhcp_start_ip != "false"
  156. - name: Check the subnet of dhcp end range
  157. shell: |
  158. IFS=. read -r i1 i2 i3 i4 <<< "{{ dhcp_end_ip }}"
  159. IFS=. read -r m1 m2 m3 m4 <<< "{{ netmask }}"
  160. printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
  161. register: dhcp_end_sub_result
  162. when: dhcp_end_ip != "false"
  163. changed_when: false
  164. - name: Set the end dhcp subnet
  165. set_fact:
  166. dhcp_end_sub: "{{ dhcp_end_sub_result.stdout }}"
  167. when: dhcp_end_ip != "false"
  168. - name: Assert dhcp_start_ip_range
  169. assert:
  170. that:
  171. - dhcp_start_ip != "false"
  172. - dhcp_start_ip != dhcp_end_ip
  173. - dhcp_start_sub == subnet
  174. - dhcp_start_sub == dhcp_end_sub
  175. success_msg: "{{ success_dhcp_range }}"
  176. fail_msg: "{{ fail_dhcp_range }}"
  177. register: dhcp_start_ip_check
  178. - name: Assert dhcp_end_ip_range
  179. assert:
  180. that:
  181. - dhcp_end_ip != "false"
  182. - dhcp_start_ip != dhcp_end_ip
  183. - dhcp_end_sub == subnet
  184. - dhcp_start_sub == dhcp_end_sub
  185. success_msg: "{{ success_dhcp_range }}"
  186. fail_msg: "{{ fail_dhcp_range }}"
  187. register: dhcp_end_ip_check
  188. - name: Create ansible vault key
  189. set_fact:
  190. vault_key: "{{ lookup('password', '/dev/null chars=ascii_letters') }}"
  191. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  192. - name: Save vault key
  193. copy:
  194. dest: "{{ vault_filename }}"
  195. content: |
  196. {{ vault_key }}
  197. owner: root
  198. force: yes
  199. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  200. - name: Encrypt input config file
  201. command: >-
  202. ansible-vault encrypt {{ input_config_filename }}
  203. --vault-password-file {{ vault_filename }}
  204. changed_when: false