Using Ansible to Configure FortiGate VLAN Interfaces to a Basic Standard
Last updated on
I had quite a few problems figuring out a basic configuration to assist with quickly creating new interfaces to a standard. The below configuration is working for me perfectly, allowing quick configuration of a new interface and DHCP server to a standard for easy micro-segmentation in my home network.
This method assumes a few things. All interfaces will be built the same way, on the same physical interface, fortilink in this case. All interfaces are VLAN, all networks are /24, and all have the same DNS and search space.
Inventory File (inventory):
Here is my Fortigate inventory file. This is using the HTTPS and API access method.
Interface Definitions (interfaces.yml)
This file contains two variables in a list, the name of the interface, always structered by <LOCATION>-<PURPOSE>-<VLAN>, and interface access.
Playbook (fortigate-interfaces.yml)
This Ansible playbook file loops through the interfaces in the interfaces.yml file, defined above.
A couple of notes here:
The VLAN ID is also the third octet for ease of use of managing my home network, so I pull out the value to define the IPs.
I use the VLAN ID for the id of the DHCP server. Fortinet supports auto-incrementing with 0, but the configuration will then not be idempotent on subsequent runs. Instead, it creates a new DHCP server, assigns it to the interface, then errors out on ip_range portion.