password_config.yml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 login_vars file is encrypted
  16. command: cat {{ login_vars_filename }}
  17. changed_when: false
  18. register: config_content
  19. - name: Decrpyt login_vars.yml
  20. command: >-
  21. ansible-vault decrypt {{ login_vars_filename }}
  22. --vault-password-file {{ vault_filename }}
  23. changed_when: false
  24. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  25. - name: Include variable file login_vars.yml
  26. include_vars: "{{ login_vars_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. cobbler_password | length < 1 or
  35. idrac_username | length < 1 or
  36. idrac_password | length < 1
  37. - name: Assert provision_password
  38. assert:
  39. that:
  40. - provision_password | length > min_length | int - 1
  41. - provision_password | length < max_length | int + 1
  42. - '"-" not in provision_password '
  43. - '"\\" not in provision_password '
  44. - '"\"" not in provision_password '
  45. - " \"'\" not in provision_password "
  46. success_msg: "{{ success_msg_provision_password }}"
  47. fail_msg: "{{ fail_msg_provision_password }}"
  48. no_log: true
  49. register: provision_password_check
  50. - name: Assert cobbler_password
  51. assert:
  52. that:
  53. - cobbler_password | length > min_length | int - 1
  54. - cobbler_password | length < max_length | int + 1
  55. - '"-" not in cobbler_password '
  56. - '"\\" not in cobbler_password '
  57. - '"\"" not in cobbler_password '
  58. - " \"'\" not in cobbler_password "
  59. success_msg: "{{ success_msg_cobbler_password }}"
  60. fail_msg: "{{ fail_msg_cobbler_password }}"
  61. no_log: true
  62. register: cobbler_password_check
  63. - name: Assert idrac_username
  64. assert:
  65. that:
  66. - idrac_username | length >= min_username_length
  67. - idrac_username | length < max_length
  68. - '"-" not in idrac_username '
  69. - '"\\" not in idrac_username '
  70. - '"\"" not in idrac_username '
  71. - " \"'\" not in idrac_username "
  72. success_msg: "{{ success_idrac_username }}"
  73. fail_msg: "{{ fail_idrac_username }}"
  74. no_log: true
  75. - name: Assert idrac_password
  76. assert:
  77. that:
  78. - idrac_password | length > min_username_length | int - 1
  79. - idrac_password | length < max_length | int + 1
  80. - '"-" not in idrac_password '
  81. - '"\\" not in idrac_password '
  82. - '"\"" not in idrac_password '
  83. - " \"'\" not in idrac_password "
  84. success_msg: "{{ success_msg_idrac_password }}"
  85. fail_msg: "{{ fail_msg_idrac_password }}"
  86. no_log: true
  87. register: idrac_password_check
  88. - name: Verify ethernet_switch_username and ethernet_switch_password are not empty
  89. assert:
  90. that:
  91. - ethernet_switch_username | length > 0
  92. - ethernet_switch_password | length > 0
  93. success_msg: "{{ ethernet_params_success_msg }}"
  94. fail_msg: "{{ ethernet_params_empty_fail_msg }}"
  95. when: ethernet_switch_support
  96. - name: Assert ethernet_switch_username
  97. assert:
  98. that:
  99. - ethernet_switch_username | length >= min_username_length
  100. - ethernet_switch_username | length < max_length
  101. - '"-" not in ethernet_switch_username '
  102. - '"\\" not in ethernet_switch_username '
  103. - '"\"" not in ethernet_switch_username '
  104. - " \"'\" not in ethernet_switch_username "
  105. success_msg: "{{ success_ethernet_switch_username }}"
  106. fail_msg: "{{ fail_ethernet_switch_username }}"
  107. when: ethernet_switch_support
  108. - name: Assert ethernet_switch_password
  109. assert:
  110. that:
  111. - ethernet_switch_password | length > min_username_length | int - 1
  112. - ethernet_switch_password | length < max_length | int + 1
  113. - '"-" not in ethernet_switch_password '
  114. - '"\\" not in ethernet_switch_password '
  115. - '"\"" not in ethernet_switch_password '
  116. - " \"'\" not in ethernet_switch_password "
  117. success_msg: "{{ success_msg_ethernet_switch_password }}"
  118. fail_msg: "{{ fail_msg_ethernet_switch_password }}"
  119. when: ethernet_switch_support
  120. no_log: true
  121. - name: Verify ib_username and ib_password are not empty
  122. assert:
  123. that:
  124. - ib_username | length > 0
  125. - ib_password | length > 0
  126. success_msg: "{{ ib_params_success_msg }}"
  127. fail_msg: "{{ ib_params_empty_fail_msg }}"
  128. when: ib_switch_support
  129. - name: Assert ib_username
  130. assert:
  131. that:
  132. - ib_username | length >= min_username_length
  133. - ib_username | length < max_length
  134. - '"-" not in ib_username '
  135. - '"\\" not in ib_username '
  136. - '"\"" not in ib_username '
  137. - " \"'\" not in ib_username "
  138. success_msg: "{{ success_ib_username }}"
  139. fail_msg: "{{ fail_ib_username }}"
  140. when: ib_switch_support
  141. - name: Assert ib_password
  142. assert:
  143. that:
  144. - ib_password | length > min_username_length | int - 1
  145. - ib_password | length < max_length | int + 1
  146. - '"-" not in ib_password '
  147. - '"\\" not in ib_password '
  148. - '"\"" not in ib_password '
  149. - " \"'\" not in ib_password "
  150. success_msg: "{{ success_msg_ib_password }}"
  151. fail_msg: "{{ fail_msg_ib_password }}"
  152. when: ib_switch_support
  153. no_log: true
  154. - name: Verify powervault_me4_username and powervault_me4_password are not empty
  155. assert:
  156. that:
  157. - powervault_me4_username | length > 0
  158. - powervault_me4_password | length > 0
  159. success_msg: "{{ pv_params_success_msg }}"
  160. fail_msg: "{{ pv_params_empty_fail_msg }}"
  161. when: powervault_support
  162. - name: Assert powervault_me4_username
  163. assert:
  164. that:
  165. - powervault_me4_username | length >= min_username_length
  166. - powervault_me4_username | length < max_length
  167. - '"-" not in powervault_me4_username '
  168. - '"\\" not in powervault_me4_username '
  169. - '"\"" not in powervault_me4_username '
  170. - " \"'\" not in powervault_me4_username "
  171. success_msg: "{{ success_powervault_me4_username }}"
  172. fail_msg: "{{ fail_powervault_me4_username }}"
  173. when: powervault_support
  174. - name: Assert powervault_me4_password
  175. assert:
  176. that:
  177. - powervault_me4_password | length > min_username_length | int - 1
  178. - powervault_me4_password | length < max_length | int + 1
  179. - '"-" not in powervault_me4_password '
  180. - '"\\" not in powervault_me4_password '
  181. - '"\"" not in powervault_me4_password '
  182. - " \"'\" not in powervault_me4_password "
  183. success_msg: "{{ success_msg_powervault_me4_password }}"
  184. fail_msg: "{{ fail_msg_powervault_me4_password }}"
  185. when: powervault_support
  186. no_log: true
  187. - name: Create ansible vault key
  188. set_fact:
  189. vault_key: "{{ lookup('password', '/dev/null chars=ascii_letters') }}"
  190. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  191. - name: Save vault key
  192. copy:
  193. dest: "{{ vault_filename }}"
  194. content: |
  195. {{ vault_key }}
  196. owner: root
  197. force: yes
  198. mode: "{{ vault_file_perm }}"
  199. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  200. - name: Encrypt input config file
  201. command: >-
  202. ansible-vault encrypt {{ login_vars_filename }}
  203. --vault-password-file {{ vault_filename }}
  204. changed_when: false