configure_2fa.yml 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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: Fetch idrac_username index
  16. community.general.idrac_redfish_info:
  17. category: Manager
  18. command: GetManagerAttributes
  19. baseuri: "{{ inventory_hostname }}"
  20. username: "{{ idrac_username }}"
  21. password: "{{ idrac_password }}"
  22. register: idrac_manager_info
  23. - name: Set idrac_attributes
  24. set_fact:
  25. idrac_attributes: "{{ idrac_manager_info.redfish_facts.entries | selectattr('Id', 'defined') | selectattr('Id', 'equalto', 'iDRACAttributes') }}"
  26. - name: Enable 2FA
  27. community.general.idrac_redfish_config:
  28. category: Manager
  29. command: SetManagerAttributes
  30. resource_id: iDRAC.Embedded.1
  31. manager_attributes:
  32. Users.2.EmailAddress: "{{ use_email_address_2fa }}"
  33. Users.2.Simple2FA: "Enabled"
  34. Users.2.UseEmail: "Enabled"
  35. baseuri: "{{ inventory_hostname }}"
  36. username: "{{ idrac_username }}"
  37. password: "{{ idrac_password }}"
  38. register: enable_2fa
  39. when: idrac_attributes[0].Attributes['Users.2.UserName'] == idrac_username
  40. - name: 2FA skip status
  41. debug:
  42. msg: "{{ enable2fa_skip_msg }}"
  43. when: idrac_attributes[0].Attributes['Users.2.UserName'] != idrac_username
  44. - name: 2FA status
  45. debug:
  46. msg: "{{ enable_2fa_msg }}"
  47. when:
  48. - idrac_attributes[0].Attributes['Users.2.UserName'] == idrac_username
  49. - not enable_2fa.failed