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

ios_config block with multiple parents #129

Closed
pffs opened this issue Sep 1, 2020 · 2 comments · May be fixed by #1050 or #778
Closed

ios_config block with multiple parents #129

pffs opened this issue Sep 1, 2020 · 2 comments · May be fixed by #1050 or #778
Assignees
Milestone

Comments

@pffs
Copy link

pffs commented Sep 1, 2020

SUMMARY

When using replace: block with ios_config with multiple layers of parents, the lines are re-applied for every level of parent.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ios_config

ANSIBLE VERSION
ansible 2.9.13
  config file = /home/arantz/ansibletest/ansible.cfg
  configured module search path = ['/home/arantz/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/arantz/ansibletest/venv/lib/python3.7/site-packages/ansible
  executable location = /home/arantz/ansibletest/venv/bin/ansible
  python version = 3.7.6 (default, Jan 19 2020, 22:34:52) [GCC 9.2.1 20200117]
CONFIGURATION
ANSIBLE_PIPELINING(/home/arantz/ansibletest/ansible.cfg) = True
CACHE_PLUGIN(/home/arantz/ansibletest/ansible.cfg) = yaml
CACHE_PLUGIN_CONNECTION(/home/arantz/ansibletest/ansible.cfg) = cache
CACHE_PLUGIN_PREFIX(/home/arantz/ansibletest/ansible.cfg) = cache
DEFAULT_CALLBACK_WHITELIST(/home/arantz/ansibletest/ansible.cfg) = ['timer']
DEFAULT_FORKS(/home/arantz/ansibletest/ansible.cfg) = 25
DEFAULT_HOST_LIST(/home/arantz/ansibletest/ansible.cfg) = ['/home/arantz/ansibletest/inventory']
DEFAULT_LOG_PATH(/home/arantz/ansibletest/ansible.cfg) = /home/arantz/ansibletest/log
HOST_KEY_CHECKING(/home/arantz/ansibletest/ansible.cfg) = False
PERSISTENT_COMMAND_TIMEOUT(/home/arantz/ansibletest/ansible.cfg) = 15
PERSISTENT_CONNECT_TIMEOUT(/home/arantz/ansibletest/ansible.cfg) = 90
OS / ENVIRONMENT

Controller is Ubuntu 18.04, devices are various Cisco IOS routers and switches.

STEPS TO REPRODUCE

ios_config task with multiple parents and replace: block

---
- hosts: all
  gather_facts: no
  tasks:
  - cisco.ios.ios_config:
      replace: block
      lines:
        - conform-action transmit
        - exceed-action drop
      parents:
        - policy-map Foo
        - class COS1
        - police rate percent 4
EXPECTED RESULTS

Should only apply the following lines:

  • policy-map Foo
  • class COS1
  • police rate percent 4
  • conform-action transmit
  • exceed-action drop
ACTUAL RESULTS
changed: [isr4k] => {
    "banners": {},
    "changed": true,
    "commands": [
        "policy-map Foo",
        "class COS1",
        "police rate percent 4",
        "conform-action transmit",
        "exceed-action drop",
        "class COS1",
        "police rate percent 4",
        "conform-action transmit",
        "exceed-action drop",
        "police rate percent 4",
        "conform-action transmit",
        "exceed-action drop"
    ],
    "invocation": {
        "module_args": {
            "after": null,
            "backup": false,
            "backup_options": null,
            "before": null,
            "defaults": false,
            "diff_against": null,
            "diff_ignore_lines": null,
            "intended_config": null,
            "lines": [
                "conform-action transmit",
                "exceed-action drop"
            ],
            "match": "line",
            "multiline_delimiter": "@",
            "parents": [
                "policy-map Foo",
                "class COS1",
                "police rate percent 4"
            ],
            "provider": null,
            "replace": "block",
            "running_config": null,
            "save_when": "never",
            "src": null
        }
    },
    "updates": [
        "policy-map Foo",
        "class COS1",
        "police rate percent 4",
        "conform-action transmit",
        "exceed-action drop",
        "class COS1",
        "police rate percent 4",
        "conform-action transmit",
        "exceed-action drop",
        "police rate percent 4",
        "conform-action transmit",
        "exceed-action drop"
    ]
}

Notice that the two lines from the lines attribute are ultimately applied 3 times. Verified on the router itself that this actually happening.

CMD: 'terminal length 0' 14:35:36 UTC Tue Sep 1 2020
CMD: 'terminal width 512' 14:35:36 UTC Tue Sep 1 2020
CMD: 'terminal width 0' 14:35:36 UTC Tue Sep 1 2020
CMD: 'show version' 14:35:36 UTC Tue Sep 1 2020
CMD: 'show running-config' 14:35:36 UTC Tue Sep 1 2020
CMD: 'configure terminal' 14:35:37 UTC Tue Sep 1 2020
CMD: 'policy-map Foo' 14:35:37 UTC Tue Sep 1 2020
CMD: 'class COS1' 14:35:37 UTC Tue Sep 1 2020
CMD: 'police rate percent 4' 14:35:37 UTC Tue Sep 1 2020
CMD: 'conform-action transmit' 14:35:37 UTC Tue Sep 1 2020
CMD: 'exceed-action drop' 14:35:37 UTC Tue Sep 1 2020
CMD: 'class COS1' 14:35:37 UTC Tue Sep 1 2020
CMD: 'police rate percent 4' 14:35:38 UTC Tue Sep 1 2020
CMD: 'conform-action transmit' 14:35:38 UTC Tue Sep 1 2020
CMD: 'exceed-action drop' 14:35:38 UTC Tue Sep 1 2020
CMD: 'police rate percent 4' 14:35:38 UTC Tue Sep 1 2020
CMD: 'conform-action transmit' 14:35:38 UTC Tue Sep 1 2020
CMD: 'exceed-action drop' 14:35:38 UTC Tue Sep 1 2020
CMD: 'end' 14:35:38 UTC Tue Sep 1 2020
%SYS-5-CONFIG_I: Configured from console by cisco on vty0 (192.168.100.2)
@justjais justjais self-assigned this Sep 2, 2020
@justjais justjais added this to the March'21 milestone Jan 20, 2021
@KB-perByte KB-perByte added the bug This issue/PR relates to a bug. label Jun 11, 2021
@KB-perByte KB-perByte removed the bug This issue/PR relates to a bug. label Aug 10, 2021
@KB-perByte KB-perByte assigned KB-perByte and unassigned justjais Aug 10, 2021
@KB-perByte
Copy link
Collaborator

HI @pffs,
looking at the structure of the playbook there is no need for the config lines to be termed under parent, as the config module tries to push the same config considering each parent at once. That is the intended behavior of the module.
The following playbook should work in your case,

  - cisco.ios.ios_config:
      replace: block
      lines:
        - policy-map Foo
        - class COS1
        - police rate percent 4
        - conform-action transmit
        - exceed-action drop

Thanks.

@pffs
Copy link
Author

pffs commented Aug 11, 2021

Unless I'm grossly misunderstanding how this module works, that doesn't seem to be accurate.

These are multiple nested config elements that would look like:

policy-map Foo
  class COS1
    police rate percent 4
    conform-action transmit
    exceed-action drop

Using your example would scope those lines to the root of the config which would result in them always running as the rest lines after the first one will never be in the root of the config.

So yes, technically your example will work, but it's not idempotent and doesn't seem the intended use of the module. It also doesn't follow the documentation for the module which lists parents as "The ordered set of parents that uniquely identify the section or hierarchy the commands should be checked against."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants