The ios_l2_interfaces task is failing with an error when attempting to apply configurations with multiple VLANs.
failed: [csw] (item={'key': 'gw1', 'value': 'Gi2/0/21'}) => {"ansible_loop_var": "interface", "changed": false, "interface": {"key": "gw1", "value": "Gi2/0/21"}, "module_stderr": "\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\r\nCommand rejected: Bad VLAN list - character #223 is a comma at end of list.\r\nkrs-csw-1(config-if)#", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error"}
Try configuring a trunk interface with a number of VLANs exceeding the "CLI limit for an IOS device for a single command."
In my case, the module generated the following single line of configuration and attempted to apply it to a switch:
When this command is executed on the device, it produces the following results:
csw(config)#interface GigabitEthernet2/0/21
csw(config-if)#$3-2004,2006-2008,2011-2012,2015-2019,2021-2026,2029-2032,2035-2038,2040-2042,2044-2046,2048,2052,2054,2056-2061,2063-2066,2068,2070-2076,2078-2079,2081-2082,2084,2086-2091,2093,2095,
Command rejected: Bad VLAN list - character #223 is a comma at end of list.
csw(config-if)#
In my setup, I generate a list of VLANs from JSON, but that's not relevant for this case. Therefore, I have created a minimal reproducible playbook.
fatal: [csw]: FAILED! => {"changed": false, "module_stderr": "5-2019,2021-2026,2029-2032,2035-2038,2040-2042,2044-2046,2048,2052,2054,2056-2061,2063-2066,2068,2070-2076,2078-2079,2081-2082,2084,2086-2091,2093,2095,\u0007\u0007\u0007\u0007\r\nCommand rejected: Bad VLAN list - character #223 is a comma at end of list.\r\nkrs-csw-1(config-if)#", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error"}
EXPECTED RESULTS
The module should generate commands that can be fed to the device without errors.
When Cisco 'show run' displays an interface with many VLANs, it breaks down the configuration into multiple lines as follows:
The module can read such representations, but it fails to produce something similar and instead tries to apply all changes in one line. When applying configurations to a device, the module should split a large single command into several parts.
ACTUAL RESULTS
The module fails to apply a large single command on the device:
# ansible-playbook -i hosts repro.yaml -vvvv
ansible-playbook [core 2.16.6]
config file = /drone/src/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.12/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-playbook
python version = 3.12.3 (main, Apr 10 2024, 14:35:18) [GCC 12.2.0] (/usr/local/bin/python)
jinja version = 3.1.3
libyaml = True
Using /drone/src/ansible.cfg as config file
setting up inventory plugins
Loading collection ansible.builtin from
host_list declined parsing /drone/src/hosts as it did not pass its verify_file() method
script declined parsing /drone/src/hosts as it did not pass its verify_file() method
auto declined parsing /drone/src/hosts as it did not pass its verify_file() method
Parsed /drone/src/hosts inventory source with ini plugin
Loading collection cisco.ios from /root/.ansible/collections/ansible_collections/cisco/ios
Loading callback plugin default of type stdout, v2.0 from /usr/local/lib/python3.12/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: repro.yaml *************************************************************************************************************************************************************************************************
Positional arguments: repro.yaml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('/drone/src/hosts',)
forks: 5
1 plays in repro.yaml
PLAY [all] ***********************************************************************************************************************************************************************************************************
TASK [configure vlan on interfaces] **********************************************************************************************************************************************************************************
task path: /drone/src/repro.yaml:6
Loading collection ansible.netcommon from /root/.ansible/collections/ansible_collections/ansible/netcommon
Loading collection ansible.utils from /root/.ansible/collections/ansible_collections/ansible/utils
redirecting (type: become) ansible.builtin.enable to ansible.netcommon.enable
<> Using network group action cisco.ios.ios for cisco.ios.ios_l2_interfaces
<> attempting to start connection
<> using connection plugin ansible.netcommon.network_cli
Found ansible-connection at path /usr/local/bin/ansible-connection
<> local domain socket does not exist, starting it
<> control socket path is /root/.ansible/pc/713152bf27
<> Loading collection ansible.builtin from
<> Loading collection ansible.netcommon from /root/.ansible/collections/ansible_collections/ansible/netcommon
<> Loading collection ansible.utils from /root/.ansible/collections/ansible_collections/ansible/utils
<> Loading collection cisco.ios from /root/.ansible/collections/ansible_collections/cisco/ios
<> local domain socket listeners started successfully
<> loaded cliconf plugin ansible_collections.cisco.ios.plugins.cliconf.ios from path /root/.ansible/collections/ansible_collections/cisco/ios/plugins/cliconf/ios.py for network_os cisco.ios.ios
<> ssh type is set to auto
<> autodetecting ssh_type
[WARNING]: ansible-pylibssh not installed, falling back to paramiko
<> ssh type is now set to paramiko
<> Loading collection ansible.builtin from
<> local domain socket path is /root/.ansible/pc/713152bf27
<> ANSIBLE_NETWORK_IMPORT_MODULES: enabled
<> ANSIBLE_NETWORK_IMPORT_MODULES: found cisco.ios.ios_l2_interfaces at /root/.ansible/collections/ansible_collections/cisco/ios/plugins/modules/ios_l2_interfaces.py
<> ANSIBLE_NETWORK_IMPORT_MODULES: running cisco.ios.ios_l2_interfaces
<> ANSIBLE_NETWORK_IMPORT_MODULES: complete
fatal: [csw]: FAILED! => {
"changed": false,
"module_stderr": "5-2019,2021-2026,2029-2032,2035-2038,2040-2042,2044-2046,2048,2052,2054,2056-2061,2063-2066,2068,2070-2076,2078-2079,2081-2082,2084,2086-2091,2093,2095,\u0007\u0007\u0007\u0007\r\nCommand rejected: Bad VLAN list - character #223 is a comma at end of list.\r\nkrs-csw-1(config-if)#",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error"
}
PLAY RECAP ***********************************************************************************************************************************************************************************************************
csw : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
SUMMARY
The
ios_l2_interfaces
task is failing with an error when attempting to apply configurations with multiple VLANs.I resolved this issue in my fork some time ago, but it was for a much older version. https://github.com/ansible-collections/cisco.ios/compare/main...serverkursk:cisco.ios:sk
I can adapt that fix to the current codebase, but it would be great to hear some hints from the maintainers about proper integration.
ISSUE TYPE
COMPONENT NAME
cisco.ios.ios_l2_interfaces
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
STEPS TO REPRODUCE
Try configuring a trunk interface with a number of VLANs exceeding the "CLI limit for an IOS device for a single command." In my case, the module generated the following single line of configuration and attempted to apply it to a switch:
When this command is executed on the device, it produces the following results:
In my setup, I generate a list of VLANs from JSON, but that's not relevant for this case. Therefore, I have created a minimal reproducible playbook.
Play results:
EXPECTED RESULTS
The module should generate commands that can be fed to the device without errors. When Cisco 'show run' displays an interface with many VLANs, it breaks down the configuration into multiple lines as follows:
The module can read such representations, but it fails to produce something similar and instead tries to apply all changes in one line. When applying configurations to a device, the module should split a large single command into several parts.
ACTUAL RESULTS
The module fails to apply a large single command on the device: