Skip to main content
longhidaniel
New Member
Dec 4, 2024 11:42 AM UTC
Solved

Ansible FortiOS, how to remove interface from virtual hardware switch?

Hello,

 

I have a 40F.

Default config has a virtual hardware switch called "lan" whose member interfaces are: "lan1", "lan2" and "lan3".

I would like to remove those member interfaces from the "lan" switch using Ansible.

 

Do you know how to do that ?

 

https://docs.ansible.com/ansible/latest/collections/fortinet/fortios/fortios_system_virtual_switch_module.html#examples

 

I tried the tasks bellow, leaving the port empty, but no success.
If I specify just one port, like lan1, it removes the others. I need to remove them all.

 

task1
- name: Remove member interfaces from "lan" virtual hardware switch
  fortinet.fortios.fortios_system_virtual_switch:
    vdom: "{{ vdom }}"
    state: "present"
    system_virtual_switch:
        name: "lan"
        port:

 

task2
- name: Remove member interfaces from "lan" virtual hardware switch
  fortinet.fortios.fortios_system_virtual_switch:
    vdom: "{{ vdom }}"
    state: "present"
    system_virtual_switch:
        name: "lan"
        port:
            -

longhidaniel
New Member
Dec 4, 2024 4:28 PM UTC

It is not possible to have a virtual hardware switch without at least one member interface.

Tried it on the GUI, so I believe the same applies to Ansible or CLI.

 

fortigate_hardware_switch.png

3 replies

Hatibi
Staff & Editor
Staff & Editor
Dec 4, 2024 3:29 PM UTC

Since you want to remove all of the entries, have you tried by adding a wildard in the port parameter?

 

Example:

port: "lan*"

Translate
longhidaniel
longhidanielAuthorAnswer
New Member
Dec 4, 2024 4:28 PM UTC

It is not possible to have a virtual hardware switch without at least one member interface.

Tried it on the GUI, so I believe the same applies to Ansible or CLI.

 

fortigate_hardware_switch.png

Translate
New Member
Apr 22, 2026 7:06 PM UTC

You have to delete the switch completely to remove all interface.

change state: “presnet” to “absent” in your task.

Remember to delete all referenced objects first for the task to run successful.

On 40F 7.2/7.4 there is a firewall address object named “lan” which blocks the deletion of the switch

Translate
Risk and Resilience in the Age of AI. An OT Thought Leadership Summit for Houston's Critical Infrastructure Leaders. Date: Thursday, December 3, 2026. Time: 8:30 am - 1:30 pm (CT). Location: The Westin Houston, Memorial City | 945 Gessner Road, Houston, TX 77024