ansible-collections / cisco.iosxr

Ansible Network Collection for Cisco IOSXR
GNU General Public License v3.0
69 stars 48 forks source link

iosxr_config remove commands #374

Open eldina07 opened 1 year ago

eldina07 commented 1 year ago
SUMMARY

Hello,

We have an issue when we try to apply a remediation configuration to a cisco XR with command use neighbor-group TEMPLATE. We have multiple prefixes which use a neighbor-group but only the first prefix is apply. The output commands from iosxr_config remove use neighbor-group TEMPLATE but we don't know why.

- cisco.iosxr.iosxr_config:
    lines: remediation_config
    replace: line
    exclusive: true

Example for remediation_config:

      neighbor 10.0.0.0/24
        use neighbor-group peer-leaf-overlay
        description first-prefix
      neighbor 10.0.1.0/24
        use neighbor-group peer-leaf-overlay
        description second-prefix
      neighbor 10.0.2.0/24
        use neighbor-group peer-leaf-overlay
       description third-prefix

Output commands:

    - neighbor 10.0.0.0/24
    - use neighbor-group peer-leaf-overlay
    - description first-prefix
    - neighbor 10.0.1.0/24
    - description second-prefix
    - neighbor 10.0.2.0/24
    - description third-prefix
    - root

So use neighbor-group is removed when it's not the first neighbor. We try with few verions, it's the same (3.3.1 and 5.0.1). This works well if we apply all configuration in one time (but we want to change few line by few lines so it's important for us)

ISSUE TYPE
COMPONENT NAME

cisco.iosxr.iosxr_config

ANSIBLE VERSION
2.12
COLLECTION VERSION
5.0.1
CONFIGURATION
CONFIG_FILE() = /etc/ansible/ansible.cfg
OS / ENVIRONMENT

debian/11

STEPS TO REPRODUCE
- cisco.iosxr.iosxr_config:
    lines: remediation_config
    replace: line
    exclusive: true

Example for remediation_config:

      neighbor 10.0.0.0/24
        use neighbor-group peer-leaf-overlay
        description first-prefix
      neighbor 10.0.1.0/24
        use neighbor-group peer-leaf-overlay
        description second-prefix
      neighbor 10.0.2.0/24
        use neighbor-group peer-leaf-overlay
       description third-prefix
EXPECTED RESULTS

Output commands:

    - neighbor 10.0.0.0/24
    - use neighbor-group peer-leaf-overlay
    - description first-prefix
    - neighbor 10.0.1.0/24
    - use neighbor-group peer-leaf-overlay
    - description second-prefix
    - neighbor 10.0.2.0/24
    - use neighbor-group peer-leaf-overlay
    - description third-prefix
    - root
ACTUAL RESULTS

Output commands:

    - neighbor 10.0.0.0/24
    - use neighbor-group peer-leaf-overlay
    - description first-prefix
    - neighbor 10.0.1.0/24
    - description second-prefix
    - neighbor 10.0.2.0/24
    - description third-prefix
    - root

If you want more informations, don't hesitate.

Frazew commented 1 year ago

I believe this issues actually lies directly into ansible.netcommon. See the following snippet:

from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import (
    NetworkConfig,
    dumps,
)

candidate_str = """
neighbor 10.0.0.0/24
  use neighbor-group peer-leaf-overlay
  description first-prefix
neighbor 10.0.1.0/24
  use neighbor-group peer-leaf-overlay
  description second-prefix
neighbor 10.0.2.0/24
  use neighbor-group peer-leaf-overlay
  description third-prefix
"""

candidate_obj = NetworkConfig(indent=2, comment_tokens=["!"])
candidate_obj.add(candidate_str.strip().splitlines())
print(dumps(candidate_obj, "raw"))

And its corresponding output:

neighbor 10.0.0.0/24
  use neighbor-group peer-leaf-overlay
  description first-prefix
neighbor 10.0.1.0/24
  description second-prefix
neighbor 10.0.2.0/24
  description third-prefix

All use neighbor-group peer-leaf-overlay lines except the first have indeed vanished from the configuration. This seems to boil down to this specific line in NetworkConfig. The add method simply disregards "duplicate" lines, no matter where they appear (within the same block or any other block, so long as the indent is the same)