ib_facts.yml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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: Infiniband Facts
  16. hosts: all
  17. gather_facts: no
  18. connection: local
  19. tasks:
  20. - name: Set credentials and variables
  21. set_fact:
  22. username: "{{ lookup('env','ANSIBLE_NET_USERNAME') }}"
  23. password: "{{ lookup('env','ANSIBLE_NET_PASSWORD') }}"
  24. filtered_dict: {}
  25. no_log: true
  26. - name: Authenticate
  27. block:
  28. - name: Authenticate to switch- "{{ inventory_hostname }}"
  29. uri:
  30. url: http://{{ inventory_hostname }}/admin/launch?script=rh&template=login&action=login
  31. method: POST
  32. body_format: form-urlencoded
  33. body:
  34. f_user_id: "{{ username }}"
  35. f_password: "{{ password }}"
  36. enter: Sign in
  37. status_code: 302
  38. register: login
  39. no_log: true
  40. - name: Verify authentication status
  41. fail:
  42. msg: "Authentication failed"
  43. when: login.set_cookie is undefined
  44. rescue:
  45. - name: Filtered response creation
  46. set_fact:
  47. filtered_dict: "{{filtered_dict |combine({item.key: item.value})}}"
  48. when: item.key not in 'invocation'
  49. with_dict: "{{ login }}"
  50. no_log: true
  51. - name: Authentication failure response
  52. fail:
  53. msg: "{{ filtered_dict }}"
  54. - name: Fetch facts from- "{{ inventory_hostname }}"
  55. uri:
  56. url: http://{{ inventory_hostname }}/admin/launch?script=json
  57. method: POST
  58. body_format: json
  59. headers:
  60. Cookie: "{{ login.set_cookie.split(';')[0] }}"
  61. body:
  62. {
  63. "commands":
  64. [
  65. "show running-config",
  66. "show version",
  67. "show inventory",
  68. "show interfaces ib status"
  69. ]
  70. }
  71. register: facts
  72. - name: Show Facts from- "{{ inventory_hostname }}"
  73. debug:
  74. msg: "{{ item.data }}"
  75. with_items: "{{ facts.json.results }}"
  76. loop_control:
  77. label: "{{ item.executed_command }}"