validate_2fa_vars.yml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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: Include provision_idrac vars
  16. include_vars: "{{ playbook_dir }}/../roles/provision_idrac/vars/main.yml"
  17. run_once: true
  18. - name: Include control_plane_common vars
  19. include_vars: "{{ playbook_dir }}/../roles/control_plane_common/vars/main.yml"
  20. run_once: true
  21. - name: Include idrac_vars.yml
  22. include_vars: "{{ playbook_dir }}/../{{ idrac_input_filename }}"
  23. run_once: true
  24. - name: Warning - waiting for one minute
  25. pause:
  26. minutes: 1
  27. prompt: "{{ enable_2fa_warning_msg }}"
  28. run_once: true
  29. - name: Set two_factor_authentication in lowercase
  30. set_fact:
  31. two_factor_authentication: "{{ two_factor_authentication | lower }}"
  32. - name: Assert two_factor_authentication value
  33. assert:
  34. that:
  35. - two_factor_authentication | length > 1
  36. - two_factor_authentication == "enabled" or two_factor_authentication == "disabled"
  37. success_msg: "{{ simple_2fa_success_msg }}"
  38. fail_msg: "{{ simple_2fa_fail_msg }}"
  39. - name: Disable 2FA message
  40. fail:
  41. msg: "{{ idrac_2fa_disable_msg }}"
  42. when: two_factor_authentication == "disabled"
  43. - block:
  44. - name: Check idrac_tools_vars.yml file is encrypted
  45. command: cat "{{ playbook_dir }}/../{{ idrac_tools_vars_filename }}"
  46. changed_when: false
  47. run_once: true
  48. register: config_content
  49. - name: Decrpyt idrac_tools_vars.yml
  50. command: >-
  51. ansible-vault decrypt "{{ playbook_dir }}/../{{ idrac_tools_vars_filename }}"
  52. --vault-password-file "{{ playbook_dir }}/../{{ idrac_tools_vaultname }}"
  53. changed_when: false
  54. run_once: true
  55. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  56. - name: Include variable file idrac_tools_vars.yml
  57. include_vars: "{{ playbook_dir }}/../{{ idrac_tools_vars_filename }}"
  58. run_once: true
  59. no_log: true
  60. - name: Validate SMTP parameters are not empty
  61. fail:
  62. msg: "{{ smtp_input_fail_msg }}"
  63. when:
  64. - dns_domain_name | length < 1 or
  65. ipv4_static_dns1 | length < 1 or
  66. ipv4_static_dns2 | length < 1 or
  67. smtp_server_ip | length < 1 or
  68. use_email_address_2fa | length < 1
  69. - name: Validate SMTP parameters if smtp_authentication is enabled
  70. fail:
  71. msg: "{{ smtp_input_fail_msg }} when smtp_authentication is enabled"
  72. when:
  73. - smtp_authentication | lower == "enabled"
  74. - smtp_username | length < 1 or
  75. smtp_password | length < 1
  76. - name: Assert use_email_address_2fa value
  77. assert:
  78. that: '"@" in use_email_address_2fa'
  79. success_msg: "{{ email_address_success_msg }}"
  80. fail_msg: "{{ email_address_fail_msg }}"
  81. - name: Encrypt idrac_tools_vars.yml
  82. command: >-
  83. ansible-vault encrypt "{{ playbook_dir }}/../{{ idrac_tools_vars_filename }}"
  84. --vault-password-file "{{ playbook_dir }}/../{{ idrac_tools_vaultname }}"
  85. changed_when: false
  86. run_once: true
  87. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  88. when: two_factor_authentication == "enabled"