Eleven idempotent Ansible modules for managing TP-Link managed switches as infrastructure-as-code. Declare your VLAN layout, port settings, and QoS policy in YAML — the collection handles the rest.
New project — lightly tested
Tested against a small number of TL-SG108E (8-port) and TL-SG116E (16-port) switches. Compatibility with other TP-Link managed switch models is untested. The module interface may change without notice. Verify each operation on your hardware before use in production — especially VLAN changes on live switches.
TP-Link managed switches have no REST API, no SSH, and no Ansible connection plugin — their only configuration interface is a frameset-based web UI. ansible-tplink wraps the tplink-tool Python SDK to expose eleven fully idempotent Ansible modules that manage these switches the same way you would any other network device.
All modules support check mode (--check),
report changed/unchanged state accurately, and are safe to run
repeatedly. The collection runs locally on the Ansible control node
(connection: local) — no agent
or SSH access to the switch is required.
VLAN configuration, port settings, QoS, storm control, bandwidth limits, LAG groups, port mirroring, IGMP snooping, and loop prevention are all declaratively managed. Maintenance tasks — reboot, backup, restore, and factory reset — are also available.
| Module | What it manages |
|---|---|
| facts | Gather switch facts (model, firmware, port count, MAC, uptime) into Ansible variables |
| system | Description, static IP, netmask, gateway, DHCP mode, LED state |
| port | Per-port enable/disable, speed/duplex, flow control — accepts a list of ports |
| trunk | LAG/trunk groups — member ports and hash algorithm |
| mirror | Port mirroring — source ports, destination port, direction |
| igmp | IGMP snooping, report suppression, and loop prevention |
| qos | QoS scheduling mode (port-based, 802.1p, DSCP, or combined) |
| bandwidth | Per-port ingress and egress bandwidth limits in kbps — accepts a list of ports |
| storm | Per-port storm control — broadcast/multicast/unknown-unicast rate limits |
| vlan | 802.1Q VLAN configuration — tagged/untagged ports, PVIDs, VLAN names, MTU VLAN, port-based VLAN |
| maintenance | Reboot, config backup to file, config restore from file, factory reset, cable diagnostics |
A minimal playbook that sets a description, configures all ports, and creates a two-VLAN layout with a trunk port:
Install from Ansible Galaxy:
The collection depends on the
tplink-tool
SDK. Place tplink_switch.py anywhere on your Python path,
or drop it into the collection's plugins/module_utils/ directory.
All modules use connection: local — set this at the
play level or in your inventory's [group:vars].
The host and password
parameters are passed directly to each module.