brocade / ansible

56 stars 33 forks source link

Calls to brocade_interface_fibrechannel returns inconsistent data structures for 'neighbors' #136

Open samuellay opened 1 year ago

samuellay commented 1 year ago

The _brocade.fos.brocade_interfacefibrechannel module returns flogis in 3 different forms. This requires a lot of extra coding to audit the switches since there are 3 special cases to deal with.

When there are multiple flogis, you get a result that is straight-forward to access in the general case:

- name: 3/3
  neighbor:
    wwn: ['20:23:00:14:38:c8:94:fc', '10:00:2e:db:64:d0:00:14', '10:00:2e:db:64:d0:00:00']

If a port has no flogis, you get something like this:

- name: 3/5
  neighbor: null

When it has one flogi you'll get:

- name: 3/10
  neighbor: {wwn: '50:00:e1:11:6c:8d:30:16'}

It would be a lot easier to extract the data if the data structure was consistent:

- name: 3/3
  neighbor:
    wwn: ['20:23:00:14:38:c8:94:fc', '10:00:2e:db:64:d0:00:14', '10:00:2e:db:64:d0:00:00']
- name: 3/5
  neighbor: 
    wwn: []
- name: 3/10
  neighbor: 
    wwn: ['50:00:e1:11:6c:8d:30:16',]

Please consider adjusting the data structures for the no-flogi and single-flogi cases to match the multi-flogi (NPIV) case.

samuellay commented 1 year ago

Here is my test case:

---
- name: Collect Interface Info from Brocade Switch
  vars:
    user_name: ansibleuser
    ansible_password: !vault |
        $ANSIBLE_VAULT;1.1;AES256
        36623134393235616264663036366137396263616533653935356138393261653533373363633235
        6635323930633564323334663335393335386332623266350a343038353462366537623538393334
        62363266346238663131393463616265653730363037393631353166336331383230316630303062
        3439313934636662660a303737656465633761393964616236653430633131616661386539666462
        6331
  hosts: all
  gather_facts: False
  connection: local
  collections:
    -brocade.fos

  tasks:

    - name: set up credentials for login
      ansible.builtin.set_fact:
        credential:
          fos_ip_addr: "{{ inventory_hostname }}"
          fos_user_name: "{{ user_name }}"
          fos_password: "{{ ansible_password }}"
          https: self
      no_log: true

    - name: Gather the switch information for Brocade SAN Switch
      brocade.fos.brocade_facts:
        credential: "{{credential}}"
        vfid: -1
        gather_subset:
          - brocade_interface_fibrechannel
      register: switch_facts
      no_log : true

    - name: Show me the neighbors
      debug:
        msg: "{{ item.neighbor }}"
      with_items: "{{ switch_facts['ansible_facts']['brocade_interface_fibrechannel'] }}"
prasad-valmeti-broadcom commented 1 year ago

This issue is addressed in FOS switch release 9.2.1 as shown below: [NO ENTRIES] "neighbor": {},

[ONE ENTRY] "neighbor": { "wwn": [ "20:10:c4:f5:7c:02:8b:08" ] },

[TWO ENTRIES] "neighbor": { "wwn": [ "20:14:c4:f5:7c:d3:be:ae", "10:00:00:10:9b:57:00:72" ] }, Please let us know, what is the switch release at your end.

prasad-valmeti-broadcom commented 1 year ago

If there are no further issues, please suggest if we can close this issue.

prasad-valmeti-broadcom commented 6 months ago

If there are no further issues, please suggest if we can close this issue.