ios_l2_interfaces - attempting to trunk port fails

I am trying to finish configuring a Cisco switch, I’ve created VLANs, Port Channels, populated VLANs

Final task is to trunk 3 ports

the docs seem to say allowd_vlan: when in fact it is allowed_vlans: then I followed the example for state replaced but using dot1q for enacapsulation

code is

`

trunk ports

  • name: trunk ports 41,42,48
    ios_l2_interfaces:
    config:
  • name: GigabitEthernet1/0/41
    trunk:
  • allowed_vlans: 10,15
    native_vlan: 10
    encapsulation: dot1q
    state: replaced

`

that syntax give me error:

`

{
“msg”: “argument trunk is of type <class ‘list’> found in ‘config’. and we were unable to convert to dict: <class ‘list’> cannot be converted to a dict”,
“exception”: " File "/tmp/ansible_ios_l2_interfaces_payload_x7bcsfrk/ansible_ios_l2_interfaces_payload.zip/ansible/module_utils/basic.py", line 1806, in _check_argument_types\n param[k] = type_checker(value)\n File "/tmp/ansible_ios_l2_interfaces_payload_x7bcsfrk/ansible_ios_l2_interfaces_payload.zip/ansible/module_utils/basic.py", line 1664, in _check_type_dict\n return check_type_dict(value)\n File "/tmp/ansible_ios_l2_interfaces_payload_x7bcsfrk/ansible_ios_l2_interfaces_payload.zip/ansible/module_utils/common/validation.py", line 433, in check_type_dict\n raise TypeError(‘%s cannot be converted to a dict’ % type(value))\n",
“invocation”: {
“module_args”: {
“config”: [
{
“name”: “GigabitEthernet1/0/41”,
“trunk”: [
{
“allowed_vlans”: “10,15”,
“native_vlan”: 10,
“encapsulation”: “dot1q”
}
]
}
],
“state”: “replaced”
}
},
“_ansible_no_log”: false,
“changed”: false
}

`

The code is straight out of the example in the 2.9 docs without the pruning_vlan and with a different type of encapsulation, so I am unsure where to go next.

I have tried a few other examples and get module failed errors… I’m just trying to keep this simple, if anyone can point out what I have done wrong I would really appreciate it.

Regards
Bill

Hi

I think it’s both: the docs are right but the example is wrong.

According to
https://docs.ansible.com/ansible/latest/modules/ios_l2_interfaces_module.html#parameter-config/trunk trunk is a dict.

The second example looks like it is incorrectly using a list (of one dict) for trunk.

Try using a dict.

I’m not sure about allowed_vlan (singular) or allowed_vlans (plural) but that’s easy to find out.

If you find the right combination please submit a bug report for the docs.

Dick

ok, so I changed code to:

`

  • name: trunk ports 41,42,48
    ios_l2_interfaces:
    config:
  • name: GigabitEthernet1/0/41
    trunk:
    allowed_vlans: 10,15
    native_vlan: 10
    pruning_vlans: 15
    encapsulation: dot1q
    state: replaced

`

and now get the error

`

{
“module_stdout”: “”,
“module_stderr”: “Traceback (most recent call last):\n File "/var/lib/awx/.ansible/tmp/ansible-local-18974ocs46j5t/ansible-tmp-1596503556.3771946-19096-91595766251735/AnsiballZ_ios_l2_interfaces.py", line 102, in \n _ansiballz_main()\n File "/var/lib/awx/.ansible/tmp/ansible-local-18974ocs46j5t/ansible-tmp-1596503556.3771946-19096-91595766251735/AnsiballZ_ios_l2_interfaces.py", line 94, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File "/var/lib/awx/.ansible/tmp/ansible-local-18974ocs46j5t/ansible-tmp-1596503556.3771946-19096-91595766251735/AnsiballZ_ios_l2_interfaces.py", line 40, in invoke_module\n runpy.run_module(mod_name=‘ansible.modules.network.ios.ios_l2_interfaces’, init_globals=None, run_name=‘main’, alter_sys=True)\n File "/usr/lib64/python3.6/runpy.py", line 205, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File "/usr/lib64/python3.6/runpy.py", line 96, in _run_module_code\n mod_name, mod_spec, pkg_name, script_name)\n File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code\n exec(code, run_globals)\n File "/tmp/ansible_ios_l2_interfaces_payload__qk3hnqu/ansible_ios_l2_interfaces_payload.zip/ansible/modules/network/ios/ios_l2_interfaces.py", line 364, in \n File "/tmp/ansible_ios_l2_interfaces_payload__qk3hnqu/ansible_ios_l2_interfaces_payload.zip/ansible/modules/network/ios/ios_l2_interfaces.py", line 359, in main\n File "/tmp/ansible_ios_l2_interfaces_payload__qk3hnqu/ansible_ios_l2_interfaces_payload.zip/ansible/module_utils/network/ios/config/l2_interfaces/l2_interfaces.py", line 67, in execute_module\n File "/tmp/ansible_ios_l2_interfaces_payload__qk3hnqu/ansible_ios_l2_interfaces_payload.zip/ansible/module_utils/connection.py", line 185, in rpc\nansible.module_utils.connection.ConnectionError: switchport trunk encapsulation dot1q\r\nswitchport trunk encapsulation dot1q\r\n ^\r\n% Invalid input detected at ‘^’ marker.\r\n\r\nCisco2960(config-if)#\n”,
“exception”: “Traceback (most recent call last):\n File "/var/lib/awx/.ansible/tmp/ansible-local-18974ocs46j5t/ansible-tmp-1596503556.3771946-19096-91595766251735/AnsiballZ_ios_l2_interfaces.py", line 102, in \n _ansiballz_main()\n File "/var/lib/awx/.ansible/tmp/ansible-local-18974ocs46j5t/ansible-tmp-1596503556.3771946-19096-91595766251735/AnsiballZ_ios_l2_interfaces.py", line 94, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File "/var/lib/awx/.ansible/tmp/ansible-local-18974ocs46j5t/ansible-tmp-1596503556.3771946-19096-91595766251735/AnsiballZ_ios_l2_interfaces.py", line 40, in invoke_module\n runpy.run_module(mod_name=‘ansible.modules.network.ios.ios_l2_interfaces’, init_globals=None, run_name=‘main’, alter_sys=True)\n File "/usr/lib64/python3.6/runpy.py", line 205, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File "/usr/lib64/python3.6/runpy.py", line 96, in _run_module_code\n mod_name, mod_spec, pkg_name, script_name)\n File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code\n exec(code, run_globals)\n File "/tmp/ansible_ios_l2_interfaces_payload__qk3hnqu/ansible_ios_l2_interfaces_payload.zip/ansible/modules/network/ios/ios_l2_interfaces.py", line 364, in \n File "/tmp/ansible_ios_l2_interfaces_payload__qk3hnqu/ansible_ios_l2_interfaces_payload.zip/ansible/modules/network/ios/ios_l2_interfaces.py", line 359, in main\n File "/tmp/ansible_ios_l2_interfaces_payload__qk3hnqu/ansible_ios_l2_interfaces_payload.zip/ansible/module_utils/network/ios/config/l2_interfaces/l2_interfaces.py", line 67, in execute_module\n File "/tmp/ansible_ios_l2_interfaces_payload__qk3hnqu/ansible_ios_l2_interfaces_payload.zip/ansible/module_utils/connection.py", line 185, in rpc\nansible.module_utils.connection.ConnectionError: switchport trunk encapsulation dot1q\r\nswitchport trunk encapsulation dot1q\r\n ^\r\n% Invalid input detected at ‘^’ marker.\r\n\r\nCisco2960(config-if)#\n”,
“msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”,
“rc”: 1,
“_ansible_no_log”: false,
“changed”: false
}

`

which makes even less sense to me… I think its saying it doesn’t like the encapsulation dot1q, which is correct and straight out of the docs as well… appreciate any advice as always and I will open up a report once I get to the bottom of this to get the examples fixed as they are plural.

Regards
BIll

Given that its a 2960, I’d venture to guess that its tripping up on the dot1q part, because, if I remember correctly, dot1q is the only supported encapsulation (no ISL). Is the behavior different if you remove that?

Brandon