# Trouble Configuring Trunk Mode on Cisco Nexus Switch using Ansible

**URL:** <https://forum.ansible.com/t/trouble-configuring-trunk-mode-on-cisco-nexus-switch-using-ansible/40705>\
**Category:** Get Help\
**Created:** [February 28, 2025, 1:44pm UTC](https://forum.ansible.com/t/trouble-configuring-trunk-mode-on-cisco-nexus-switch-using-ansible/40705 "2025-02-28T13:44:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanielSilva](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/danielsilva/32/7611_2.png) [@DanielSilva](https://forum.ansible.com/u/DanielSilva)\
**Post date:** [February 28, 2025, 1:44pm UTC](https://forum.ansible.com/t/trouble-configuring-trunk-mode-on-cisco-nexus-switch-using-ansible/40705/1 "2025-02-28T13:44:09Z")

</div>

Good morning everyone, I am trying to make the following configurations that would be done manually on a Cisco Nexus switch:

```auto
interface Eth1/<INTERFACE-ID-DOWNLINK>
  description <HDNUMBER>
  switchport
  switchport mode trunk
  switchport trunk allowed vlan <VLAN-ID>
  mtu 9216
  no shutdown
  exit

```

I found the `cisco.nxos.nxos_interface` module and I was able to define the following functions:

```auto
- cisco.nxos.nxos_interfaces:
    config:
      - name: "{{porta}}"
        description: "{{hdnumber}}"
        mtu: 9216
        enabled: true

```

However, when I tried to use the `nxos.nxos_config` to set the switchport as trunk, I got the following error:

```auto
- cisco.nxos.nxos_config:
    lines:
      - interface {{porta}} # Define the interface (replace {{porta}} with the interface name, e.g., Ethernet1/1)
      - switchport mode trunk # Set the interface as trunk
      - switchport trunk allowed vlan 10,20 # Set the allowed VLANs on the trunk
      - switchport trunk native vlan 1 # Set the native VLAN

```

ERROR:

```auto
TASK [cisco.nxos.nxos_config] ******************************************************************
fatal: [cloudstorage_primary]: FAILED! => {"changed": false, "msg": "switchport mode trunk\r\r\n ^\r\n% Invalid command at '^' marker.\r\n\rTESTE-SPEEDbUMPS(config)# "}

```

Could someone help me?

---

<div class="post-metadata">

**Author:** ![wayt](https://avatars.discourse-cdn.com/v4/letter/w/3be4f8/32.png) [@wayt](https://forum.ansible.com/u/wayt)\
**Post date:** [February 28, 2025, 4:40pm UTC](https://forum.ansible.com/t/trouble-configuring-trunk-mode-on-cisco-nexus-switch-using-ansible/40705/2 "2025-02-28T16:40:43Z")

</div>

Try:

```ansible
- cisco.nxos.nxos_config:
    lines:
      - switchport mode trunk
      - switchport trunk allowed vlan 10,20
      - switchport trunk native vlan 1
    parents:
      - "interface {{ porta }}"

```

I prefer network resource modules like `cisco.nxos.nxos_interface` because it will handle far more edge cases when resolving the intended state of your network device than the `*_config` modules provide.
