cisco.nxos icon indicating copy to clipboard operation
cisco.nxos copied to clipboard

[nxos_static_routes] Add support for `ip(v6) route static bfd` commands

Open guoliangdai-personal opened this issue 5 years ago • 1 comments

SUMMARY

We configure bfd in the cisco nxos switch with the command: ip route static bfd Vlan11 xxx, while when we use cisco.nxos.nxos_static_routes to manage the static route, we below code to mange it

- name: Configure static routes
  cisco.nxos.nxos_static_routes:
    config:
    - address_families:
      - afi: ipv4
        routes:
        - dest: 0.0.0.0/0
          next_hops:
          - forward_router_address: 10.16.8.254
we get this error:
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'NoneType' object has no attribute 'group'
fatal: [dx-core-prod-001.dx.corp.pony.ai]: FAILED! => changed=false 
  module_stderr: |-
    Traceback (most recent call last):
      File "<stdin>", line 102, in <module>
      File "<stdin>", line 94, in _ansiballz_main
      File "<stdin>", line 40, in invoke_module
      File "/usr/lib/python3.5/runpy.py", line 196, in run_module
        return _run_module_code(code, init_globals, run_name, mod_spec)
      File "/usr/lib/python3.5/runpy.py", line 96, in _run_module_code
        mod_name, mod_spec, pkg_name, script_name)
      File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "/tmp/ansible_cisco.nxos.nxos_static_routes_payload___timhni/ansible_cisco.nxos.nxos_static_routes_payload.zip/ansible_collections/cisco/nxos/plugins/modules/nxos_static_routes.py", line 476, in <module>
      File "/tmp/ansible_cisco.nxos.nxos_static_routes_payload___timhni/ansible_cisco.nxos.nxos_static_routes_payload.zip/ansible_collections/cisco/nxos/plugins/modules/nxos_static_routes.py", line 471, in main
      File "/tmp/ansible_cisco.nxos.nxos_static_routes_payload___timhni/ansible_cisco.nxos.nxos_static_routes_payload.zip/ansible_collections/cisco/nxos/plugins/module_utils/network/nxos/config/static_routes/static_routes.py", line 93, in execute_module
      File "/tmp/ansible_cisco.nxos.nxos_static_routes_payload___timhni/ansible_cisco.nxos.nxos_static_routes_payload.zip/ansible_collections/cisco/nxos/plugins/module_utils/network/nxos/config/static_routes/static_routes.py", line 56, in get_static_routes_facts
      File "/tmp/ansible_cisco.nxos.nxos_static_routes_payload___timhni/ansible_cisco.nxos.nxos_static_routes_payload.zip/ansible_collections/cisco/nxos/plugins/module_utils/network/nxos/facts/facts.py", line 129, in get_facts
      File "/tmp/ansible_cisco.nxos.nxos_static_routes_payload___timhni/ansible_cisco.nxos.nxos_static_routes_payload.zip/ansible_collections/ansible/netcommon/plugins/module_utils/network/common/facts/facts.py", line 131, in get_network_resources_facts
      File "/tmp/ansible_cisco.nxos.nxos_static_routes_payload___timhni/ansible_cisco.nxos.nxos_static_routes_payload.zip/ansible_collections/cisco/nxos/plugins/module_utils/network/nxos/facts/static_routes/static_routes.py", line 100, in populate_facts
      File "/tmp/ansible_cisco.nxos.nxos_static_routes_payload___timhni/ansible_cisco.nxos.nxos_static_routes_payload.zip/ansible_collections/cisco/nxos/plugins/module_utils/network/nxos/facts/static_routes/static_routes.py", line 239, in render_config
      File "/tmp/ansible_cisco.nxos.nxos_static_routes_payload___timhni/ansible_cisco.nxos.nxos_static_routes_payload.zip/ansible_collections/cisco/nxos/plugins/module_utils/network/nxos/facts/static_routes/static_routes.py", line 174, in get_command
      File "/tmp/ansible_cisco.nxos.nxos_static_routes_payload___timhni/ansible_cisco.nxos.nxos_static_routes_payload.zip/ansible_collections/cisco/nxos/plugins/module_utils/network/nxos/facts/static_routes/static_routes.py", line 121, in get_inner_dict
    AttributeError: 'NoneType' object has no attribute 'group'
  module_stdout: ''
  msg: |-
    MODULE FAILURE
    See stdout/stderr for the exact error
  rc: 1
ISSUE TYPE
  • Bug Report
COMPONENT NAME

module cisco.nxos.nxos_static_routes

ANSIBLE VERSION
ansible 2.9.10
  config file = /home/gz-guoliangdai/work/ponyai/.sub-repos/os-environment/ansible/ansible.cfg
  configured module search path = ['/home/gz-guoliangdai/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/gz-guoliangdai/.local/lib/python3.5/site-packages/ansible
  executable location = /home/gz-guoliangdai/.local/bin/ansible
  python version = 3.5.2 (default, Oct  7 2020, 17:19:02) [GCC 5.4.0 20160609]
CONFIGURATION

OS / ENVIRONMENT

ubuntu 16.04

STEPS TO REPRODUCE

EXPECTED RESULTS
ACTUAL RESULTS

After some digging, we find in the file: facts/static_routes/static_routes.py: L121

119         conf = re.sub(r"\s*ip(v6)? route", "", conf)
120         # strip 'ip route'
121         inner_dict["dest"] = re.match(r"^\s*(\S+\/\d+) .*", conf).group(1)

the module use re to get the destination, while the re could not match the configuration below:

ip route static bfd Vlan11 xxxx

Also it did not catch the exception, so the module failed.

guoliangdai-personal avatar Dec 03 '20 07:12 guoliangdai-personal

A temporary fix for this issue has been pushed here: https://github.com/ansible-collections/cisco.nxos/pull/317. This will prevent the traceback and will allow existing options to work. Full support for BFD will require a considerable amount of rework of the existing code and will be added in a later release. As such, we will be tracking this ticket as a Feature Request for BFD command support for the static routes module.

NilashishC avatar Jun 28 '21 07:06 NilashishC