# ios\_l2\_interfaces - attempting to trunk port fails

**URL:** <https://forum.ansible.com/t/ios-l2-interfaces-attempting-to-trunk-port-fails/33543>\
**Category:** Ansible Project\
**Created:** [August 3, 2020, 10:33pm UTC](https://forum.ansible.com/t/ios-l2-interfaces-attempting-to-trunk-port-fails/33543 "2020-08-03T22:33:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![william.dossett](https://avatars.discourse-cdn.com/v4/letter/w/b782af/32.png) [@william.dossett](https://forum.ansible.com/u/william.dossett)\
**Post date:** [August 3, 2020, 10:33pm UTC](https://forum.ansible.com/t/ios-l2-interfaces-attempting-to-trunk-port-fails/33543/1 "2020-08-03T22:33:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [August 4, 2020, 12:10am UTC](https://forum.ansible.com/t/ios-l2-interfaces-attempting-to-trunk-port-fails/33543/2 "2020-08-04T00:10:54Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![william.dossett](https://avatars.discourse-cdn.com/v4/letter/w/b782af/32.png) [@william.dossett](https://forum.ansible.com/u/william.dossett)\
**Post date:** [August 4, 2020, 1:20am UTC](https://forum.ansible.com/t/ios-l2-interfaces-attempting-to-trunk-port-fails/33543/3 "2020-08-04T01:20:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brandon\_Robare](https://avatars.discourse-cdn.com/v4/letter/b/41988e/32.png) [@Brandon\_Robare](https://forum.ansible.com/u/Brandon_Robare)\
**Post date:** [August 6, 2020, 5:13am UTC](https://forum.ansible.com/t/ios-l2-interfaces-attempting-to-trunk-port-fails/33543/4 "2020-08-06T05:13:42Z")

</div>

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
