password_config.yml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. # Copyright 2021 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. no_log: true
  20. - name: Decrpyt login_vars.yml
  21. command: >-
  22. ansible-vault decrypt {{ login_vars_filename }}
  23. --vault-password-file {{ vault_filename }}
  24. changed_when: false
  25. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  26. - name: Include variable file login_vars.yml
  27. include_vars: "{{ login_vars_filename }}"
  28. no_log: true
  29. - name: Validate input parameters are not empty
  30. fail:
  31. msg: "{{ login_input_config_failure_msg }}"
  32. register: input_config_check
  33. when:
  34. - provision_password | length < 1 or
  35. cobbler_password | length < 1 or
  36. idrac_username | length < 1 or
  37. idrac_password | length < 1
  38. - name: Assert provision credentials
  39. block:
  40. - name: Assert provision_password
  41. assert:
  42. that:
  43. - provision_password | length > min_length | int - 1
  44. - provision_password | length < max_length | int + 1
  45. - '"-" not in provision_password '
  46. - '"\\" not in provision_password '
  47. - '"\"" not in provision_password '
  48. - " \"'\" not in provision_password "
  49. no_log: true
  50. rescue:
  51. - name: Provision password validation check
  52. fail:
  53. msg: "{{ fail_msg_provision_password }}"
  54. - name: Assert cobbler credentials
  55. block:
  56. - name: Assert cobbler_password
  57. assert:
  58. that:
  59. - cobbler_password | length > min_length | int - 1
  60. - cobbler_password | length < max_length | int + 1
  61. - '"-" not in cobbler_password '
  62. - '"\\" not in cobbler_password '
  63. - '"\"" not in cobbler_password '
  64. - " \"'\" not in cobbler_password "
  65. no_log: true
  66. rescue:
  67. - name: Cobbler password validation check
  68. fail:
  69. msg: "{{ fail_msg_cobbler_password }}"
  70. - name: Assert idrac credentials
  71. block:
  72. - name: Assert idrac_username and idrac_password
  73. assert:
  74. that:
  75. - idrac_username | length >= min_username_length
  76. - idrac_username | length < max_length
  77. - '"-" not in idrac_username '
  78. - '"\\" not in idrac_username '
  79. - '"\"" not in idrac_username '
  80. - " \"'\" not in idrac_username "
  81. - idrac_password | length > min_username_length | int - 1
  82. - idrac_password | length < max_length | int + 1
  83. - '"-" not in idrac_password '
  84. - '"\\" not in idrac_password '
  85. - '"\"" not in idrac_password '
  86. - " \"'\" not in idrac_password "
  87. no_log: true
  88. rescue:
  89. - name: idrac credentials validation check
  90. fail:
  91. msg: "{{ fail_msg_idrac_credentials }}"
  92. - name: Assert username and password for ethernet switches
  93. block:
  94. - name: Verify ethernet_switch_username and ethernet_switch_password are not empty
  95. assert:
  96. that:
  97. - ethernet_switch_username | length >= min_username_length
  98. - ethernet_switch_username | length < max_length
  99. - '"-" not in ethernet_switch_username '
  100. - '"\\" not in ethernet_switch_username '
  101. - '"\"" not in ethernet_switch_username '
  102. - " \"'\" not in ethernet_switch_username "
  103. - ethernet_switch_password | length > min_username_length | int - 1
  104. - ethernet_switch_password | length < max_length | int + 1
  105. - '"-" not in ethernet_switch_password '
  106. - '"\\" not in ethernet_switch_password '
  107. - '"\"" not in ethernet_switch_password '
  108. - " \"'\" not in ethernet_switch_password "
  109. no_log: true
  110. rescue:
  111. - name: ethernet switch credentials validation check
  112. fail:
  113. msg: "{{ fail_msg_ethernet_credentials }}"
  114. when: ethernet_switch_support
  115. - name: Assert username and password for IB switches
  116. block:
  117. - name: Assert ib_username and ib_password
  118. assert:
  119. that:
  120. - ib_username | length >= min_username_length
  121. - ib_username | length < max_length
  122. - '"-" not in ib_username '
  123. - '"\\" not in ib_username '
  124. - '"\"" not in ib_username '
  125. - " \"'\" not in ib_username "
  126. - ib_password | length > min_username_length | int - 1
  127. - ib_password | length < max_length | int + 1
  128. - '"-" not in ib_password '
  129. - '"\\" not in ib_password '
  130. - '"\"" not in ib_password '
  131. - " \"'\" not in ib_password "
  132. no_log: true
  133. rescue:
  134. - name: IB switch credentials validation check
  135. fail:
  136. msg: "{{ fail_msg_ib_credentials }}"
  137. when: ib_switch_support
  138. - name: Assert username and password for powervault me4
  139. block:
  140. - name: Assert powervault_me4_username and powervault_me4_password
  141. assert:
  142. that:
  143. - powervault_me4_username | length >= min_username_length
  144. - powervault_me4_username | length < max_length
  145. - '"-" not in powervault_me4_username '
  146. - '"\\" not in powervault_me4_username '
  147. - '"\"" not in powervault_me4_username '
  148. - " \"'\" not in powervault_me4_username "
  149. - powervault_me4_password | length > min_length | int - 1
  150. - powervault_me4_password | length < max_length | int + 1
  151. - '"-" not in powervault_me4_password '
  152. - '"," not in powervault_me4_password '
  153. - '"." not in powervault_me4_password '
  154. - '"<" not in powervault_me4_password '
  155. - '"\\" not in powervault_me4_password '
  156. - '"\"" not in powervault_me4_password '
  157. - " \"'\" not in powervault_me4_password "
  158. - powervault_me4_password | regex_search('^(?=.*[a-z]).+$')
  159. - powervault_me4_password | regex_search('^(?=.*[A-Z]).+$')
  160. - powervault_me4_password | regex_search('^(?=.*\\d).+$')
  161. - powervault_me4_password | regex_search('^(?=.*[!#$%&()*+/:;=>?@^_`{} ~]).+$')
  162. no_log: true
  163. rescue:
  164. - name: Powervault me4 credentials validation check
  165. fail:
  166. msg: "{{ fail_msg_me4_credentials }}"
  167. when: powervault_support
  168. - name: Create ansible vault key
  169. set_fact:
  170. vault_key: "{{ lookup('password', '/dev/null chars=ascii_letters') }}"
  171. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  172. - name: Save vault key
  173. copy:
  174. dest: "{{ vault_filename }}"
  175. content: |
  176. {{ vault_key }}
  177. owner: root
  178. force: yes
  179. mode: "{{ vault_file_perm }}"
  180. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  181. - name: Encrypt input config file
  182. command: >-
  183. ansible-vault encrypt {{ login_vars_filename }}
  184. --vault-password-file {{ vault_filename }}
  185. changed_when: false
  186. - name: Update login_vars.yml permission
  187. file:
  188. path: "{{ login_vars_filename }}"
  189. mode: "{{ file_perm }}"