authenticate.yml 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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: Set Credentials for IB switch
  16. set_fact:
  17. username: "{{ lookup('env','ANSIBLE_NET_USERNAME') }}"
  18. password: "{{ lookup('env','ANSIBLE_NET_PASSWORD') }}"
  19. global_config: false
  20. interface_config: false
  21. filtered_dict: {}
  22. no_log: true
  23. - name: Authenticate
  24. block:
  25. - name: Authenticate to switch- "{{ inventory_hostname }}"
  26. uri:
  27. url: http://{{ inventory_hostname }}/admin/launch?script=rh&template=login&action=login
  28. method: POST
  29. body_format: form-urlencoded
  30. body:
  31. f_user_id: "{{ username }}"
  32. f_password: "{{ password }}"
  33. enter: Sign in
  34. status_code: 302
  35. register: login
  36. no_log: true
  37. - name: Verify authentication status
  38. fail:
  39. msg: "Authentication failed"
  40. when: login.set_cookie is undefined
  41. rescue:
  42. - name: Filtered response creation
  43. set_fact:
  44. filtered_dict: "{{ filtered_dict |combine({ item.key: item.value }) }}"
  45. when: item.key not in 'invocation'
  46. with_dict: "{{ login }}"
  47. no_log: true
  48. - name: Authentication failure response
  49. fail:
  50. msg: "{{ filtered_dict }}"