ansible-collections / dellemc.enterprise_sonic

Ansible Network Collection for Enterprise SONiC Distribution by Dell Technologies
GNU General Public License v3.0
42 stars 59 forks source link

[BUG]: sonic_interfaces returns errors #386

Closed twomassz closed 3 months ago

twomassz commented 3 months ago

Bug Description

when running the following playbook:

---
- hosts: fabric
  connection: httpapi
  gather_facts: false
  collections:
    - dellemc.enterprise_sonic

  tasks:
    - name: Create Interfaces
      sonic_interfaces:
        config:
          - name: Eth1/8
            description: Uplink
            enabled: true
          - name: Eth1/9
            description: Uplink
            enabled: true
          - name: Loopback0
            description: RouterID
          - name: Loopback1
            description: VTEP

The following errors are returned:

TASK [Create Interfaces] **** task path: /etc/ansible/test.yaml:8 redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi redirecting (type: action) dellemc.enterprise_sonic.sonic_interfaces to dellemc.enterprise_sonic.sonic redirecting (type: action) dellemc.enterprise_sonic.sonic_interfaces to dellemc.enterprise_sonic.sonic The full traceback is: File "/home/ansible/.ansible/collections/ansible_collections/ansible/netcommon/plugins/module_utils/network/common/facts/facts.py", line 128, in get_network_resources_facts inst.populate_facts(self._connection, self.ansible_facts, data) File "/home/ansible/.ansible/collections/ansible_collections/dellemc/enterprise_sonic/plugins/module_utils/network/sonic/facts/interfaces/interfaces.py", line 87, in populate_facts obj = self.transform_config(obj) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ansible/.ansible/collections/ansible_collections/dellemc/enterprise_sonic/plugins/module_utils/network/sonic/facts/interfaces/interfaces.py", line 117, in transform_config exist_cfg = conf['config']


fatal: [leaf-1-1]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "config": [
                {
                    "advertised_speed": null,
                    "auto_negotiate": null,
                    "description": "Uplink",
                    "enabled": true,
                    "fec": null,
                    "mtu": null,
                    "name": "Eth1/8",
                    "speed": null
                },
                {
                    "advertised_speed": null,
                    "auto_negotiate": null,
                    "description": "Uplink",
                    "enabled": true,
                    "fec": null,
                    "mtu": null,
                    "name": "Eth1/9",
                    "speed": null
                },
                {
                    "advertised_speed": null,
                    "auto_negotiate": null,
                    "description": "RouterID",
                    "enabled": null,
                    "fec": null,
                    "mtu": null,
                    "name": "Loopback0",
                    "speed": null
                },
                {
                    "advertised_speed": null,
                    "auto_negotiate": null,
                    "description": "VTEP",
                    "enabled": null,
                    "fec": null,
                    "mtu": null,
                    "name": "Loopback1",
                    "speed": null
                }
            ],
            "state": "merged"
        }
    },
    "msg": "'config'"
}

### Product Name

Dell Enterprise SONiC 4.2.1 (GNS3)

### Component or Module Name

sonic_interfaces

### DellEMC Enterprise SONiC Ansible Collection Version

2.4.0

### SONiC Software Version

Enterprise_SONiC_OS_4.2.1 (GNS3)

### Configuration

ansible@cve-ubuntu01-dhcp:~$ ansible-config dump --changed-only
CONFIG_FILE() = /etc/ansible/ansible.cfg
DEPRECATION_WARNINGS(/etc/ansible/ansible.cfg) = False
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False

##########################
ansible-playbook [core 2.16.7]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ansible/venv/ansible/lib/python3.12/site-packages/ansible
  ansible collection location = /home/ansible/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/ansible/venv/ansible/bin/ansible-playbook
  python version = 3.12.3 (main, Apr 10 2024, 05:33:47) [GCC 13.2.0] (/home/ansible/venv/ansible/bin/python)
  jinja version = 3.1.4
  libyaml = True

### Steps to Reproduce

````
---
- hosts: leaf-1-1
  connection: httpapi
  gather_facts: false
  collections:
    - dellemc.enterprise_sonic

  tasks:
    - name: Create Interfaces
      sonic_interfaces:
        config:
          - name: Eth1/8
            description: Uplink
            enabled: true
          - name: Eth1/9
            description: Uplink
            enabled: true
          - name: Loopback0
            description: RouterID
          - name: Loopback1
            description: VTEP`

### Expected Behavior

Creation/update of interfaces 

### Actual Behavior

The full traceback is:
  File "/home/ansible/.ansible/collections/ansible_collections/ansible/netcommon/plugins/module_utils/network/common/facts/facts.py", line 128, in get_network_resources_facts
    inst.populate_facts(self._connection, self.ansible_facts, data)
  File "/home/ansible/.ansible/collections/ansible_collections/dellemc/enterprise_sonic/plugins/module_utils/network/sonic/facts/interfaces/interfaces.py", line 87, in populate_facts
    obj = self.transform_config(obj)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ansible/.ansible/collections/ansible_collections/dellemc/enterprise_sonic/plugins/module_utils/network/sonic/facts/interfaces/interfaces.py", line 117, in transform_config
    exist_cfg = conf['config']
                ~~~~^^^^^^^^^^
fatal: [leaf-1-1]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "config": [
                {
                    "advertised_speed": null,
                    "auto_negotiate": null,
                    "description": "Uplink",
                    "enabled": true,
                    "fec": null,
                    "mtu": null,
                    "name": "Eth1/8",
                    "speed": null
                },
                {
                    "advertised_speed": null,
                    "auto_negotiate": null,
                    "description": "Uplink",
                    "enabled": true,
                    "fec": null,
                    "mtu": null,
                    "name": "Eth1/9",
                    "speed": null
                },
                {
                    "advertised_speed": null,
                    "auto_negotiate": null,
                    "description": "RouterID",
                    "enabled": null,
                    "fec": null,
                    "mtu": null,
                    "name": "Loopback0",
                    "speed": null
                },
                {
                    "advertised_speed": null,
                    "auto_negotiate": null,
                    "description": "VTEP",
                    "enabled": null,
                    "fec": null,
                    "mtu": null,
                    "name": "Loopback1",
                    "speed": null
                }
            ],
            "state": "merged"
        }
    },
    "msg": "'config'"
}

PLAY RECAP **********************************************************************************************************************************************************************************************************************************
leaf-1-1                   : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

### Logs

See previous

### Screenshots

_No response_

### Additional Information

_No response_
kerry-meyer commented 3 months ago

Summary:

Fixed by interfaces, vlans - Fix exception when gathering facts

Details: This problem was caused by a combination of the following factors:

The bug in the enterprise_sonic handling of fetched interface configuration described above was fixed by the following PR:

interfaces, vlans - Fix exception when gathering facts

This PR was merged into the enterprise_sonic Ansible resource module collection on May 6, 2024, and will be included in the upcoming 2.5.0 release. The submitter verified that, with the fix in place (via installation of the latest pre-release version as described in "https://github.com/ansible-collections/dellemc.enterprise_sonic/wiki/Installation-of-the-latest-pre-release-version"). the problem does not occur.