HuaweiSwitch / CloudEngine-Ansible

Ansible modules to automate HUAWEI CloudEngine switches
GNU General Public License v3.0
144 stars 51 forks source link

Failure when trying to configure BGP EVPN Neighbor in ce_bgp_neighbor_af.py #52

Closed kpostrup closed 5 years ago

kpostrup commented 6 years ago

When trying to configure a BGP peer with address-family evpn.

- name: "Configure BGP peer(s) on EVPN address-family"
  ce_bgp_neighbor_af:
    state: present
    remote_address: "192.168.1.2"
    af_type: "evpn"
    vrf_name: _public_
    provider: "{{ cli }}"

I get the following error

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: UnboundLocalError: local variable 'cmd' referenced before assignment
failed: [x.x.x.x] (item={'value': {u'local_if_name': u'100GE1/0/3', u'remote_as': 65001}, 'key': u'192.168.1.2'}) => {"changed": false, "item": {"key": "192.168.1.2", "value": {"local_if_name": "100GE1/0/3", "remote_as": 65001}}, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_UVozq5/ansible_module_ce_bgp_neighbor_af.py\", line 2584, in <module>\n    main()\n  File \"/tmp/ansible_UVozq5/ansible_module_ce_bgp_neighbor_af.py\", line 2528, in main\n    cmd = ce_bgp_peer_af_obj.merge_bgp_peer_af(module=module)\n  File \"/tmp/ansible_UVozq5/ansible_module_ce_bgp_neighbor_af.py\", line 1784, in merge_bgp_peer_af\n    cmds.append(cmd)\nUnboundLocalError: local variable 'cmd' referenced before assignment\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 245}

It looks like there is a missing statement for the EVPN address family, in ce_bgp_neighbor_af.py

        cmds = []
        if af_type == "ipv4uni":
            cmd = "ipv4-family unicast"
        elif af_type == "ipv4multi":
            cmd = "ipv4-family multicast"
        elif af_type == "ipv6uni":
            cmd = "ipv6-family unicast"
        cmds.append(cmd)
        cmd = "peer %s" % remote_address
        cmds.append(cmd)
yuandongx commented 6 years ago

The problem has been repaired. Look at the code url: https://github.com/HuaweiSwitch/CloudEngine-Ansible/blob/master/library/ce_bgp_neighbor_af.py