Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iosxr_config remove commands #374

Open
eldina07 opened this issue Apr 17, 2023 · 1 comment
Open

iosxr_config remove commands #374

eldina07 opened this issue Apr 17, 2023 · 1 comment
Assignees

Comments

@eldina07
Copy link

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
  • Bug Report
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.

@eldina07 eldina07 changed the title iosxr_config remove lines iosxr_config remove commands Apr 17, 2023
@Frazew
Copy link

Frazew commented Jun 15, 2023

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)

@Ruchip16 Ruchip16 assigned Ruchip16 and unassigned ashwini-mhatre Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants