Using FortiManager device database variables in Jinja
You can use FortiManager variables in Jinja script to retrieve data from the FortiManager Device Database.
The following FortiManager variables are supported:
Supported Device Database Variables |
Supported System Interface Variables |
---|---|
|
|
This topic includes the following:
- Using FortiManager variables
- Example 1: Creating physical interfaces for FortiGate-VMs
- Example 2: View the device attributes for FortiGate-VMs
- Example 3: View the interface attributes for each physical interface on a device
Using FortiManager variables
To use variables in a Jinja template:
- Go to Device Manager > Provisioning Templates > CLI Template.
- Create a new CLI template.
- Select the Type as Jinja Script.
- Configure the Script Details with FortiManager variables. For example, you can use DVMDB.name as a variable to get the device name from the Device Database:
config system global
set hostname {{DVMDB.name}}
end
When viewing the Install Preview for the CLI Template, the variable DVMDB.name is replaced with the Name value for the selected device.
Example 1: Creating physical interfaces for FortiGate-VMs
A user is setting up a FGT-VM64 model device on FortiManager. When setting up a FortiGate-VM, the user needs to execute a script to create the physical interfaces, however, when deploying a FortiGate hardware platform, generating physical interfaces is not necessary. Previously, the user needed to create a separate device group for their FortiGate-VM devices and then runs a script to create the physical interfaces for VM devices inside the device group.
Using Jinja, the same CLI template can be applied to ANY new devices (hardware or VM-based) by using a script with FortiManager variables to determine the platform of the device and using an "if" statement to ensure that the script runs only on FortiGate-VM devices.
Example script:
{% if 'FortiGate-VM64' in DVMDB.platform -%}
config system interface
{%- for i in range(0, vm_interface_number|int) %}
edit port{{i+1}}
set vdom root
set type physical
next
{%- endfor %}
end
{%- endif %}
Previewing the script on a device shows how the variables are applied.
Example 2: View the device attributes for FortiGate-VMs
Example script:
{%- if DVMDB.platform == 'FortiGate-VM64' %}
Name: {{DVMDB.name}}
Serial: {{DVMDB.serial}}
OS TYPE: {{DVMDB.os_type}}
Platform: {{DVMDB.platform}}
Version: {{DVMDB.version}}
hostname: {{DVMDB.hostname}}
UUID: {{DVMDB.mgmt_uuid}}
Mgmt Interface IP : {{DVMDB.mgmt_if}}
IP: {{DVMDB.ip}}
Tunnel IP : {{DVMDB.tunnel_ip}}
Description: {{DVMDB.description}}
os_type: {{DVMDB.os_type}}
{%- endif %}
The rendered result for the script:
=======================
Name: vlan171_0040
Serial: FGVM08HZ20311040
OS TYPE: FortiGate
Platform: FortiGate-VM64
Version: 7.4.0
hostname: 3456-abc
UUID: 9c50812a-caa8-51ed-958a-4e7800e5139a
Mgmt Interface IP : port1
IP: 10.8.71.40
Tunnel IP : 169.254.0.12
Description:
os_type: FortiGate
Example 3: View the interface attributes for each physical interface on a device
Example script:
{%- for intf in DEVDB_system_interface %}
{%- if intf.type == 'physical' %}
Interface Name: {{intf.name}}
-- Interface Allowaccess: {{intf.allowaccess}}
-- Interface Type: {{intf.type}}
-- Interface IP: {{intf.ip}}
-- Interface Mode: {{intf.mode}}
-- Interface VDOM: {{intf.vdom}}
{%- endif %}
{%- endfor %}
The rendered result for the script:
===============================
Interface Name: port1
-- Interface Allowaccess: ping
-- Interface Type: physical
-- Interface IP: 10.8.71.40
-- Interface Mode: static
-- Interface VDOM: "root"
Interface Name: port2
-- Interface Allowaccess: https
-- Interface Type: physical
-- Interface IP: 101.71.40.1
-- Interface Mode: static
-- Interface VDOM: "root"
Interface Name: port3
-- Interface Allowaccess: ping
-- Interface Type: physical
-- Interface IP: 200.71.40.1
-- Interface Mode: static
-- Interface VDOM: "root"
Interface Name: port4
-- Interface Allowaccess:
-- Interface Type: physical
-- Interface IP: 0.0.0.0
-- Interface Mode: static
-- Interface VDOM: "root"
Interface Name: port5
-- Interface Allowaccess: ping
-- Interface Type: physical
-- Interface IP: 172.71.40.1
-- Interface Mode: static
-- Interface VDOM: "root"
Interface Name: port6
-- Interface Allowaccess:
-- Interface Type: physical
-- Interface IP: 0.0.0.0
-- Interface Mode: static
-- Interface VDOM: "root"
Interface Name: port7
-- Interface Allowaccess:
-- Interface Type: physical
-- Interface IP: 0.0.0.0
-- Interface Mode: static
-- Interface VDOM: "root"
Interface Name: port8
-- Interface Allowaccess:
-- Interface Type: physical
-- Interface IP: 0.0.0.0
-- Interface Mode: static
-- Interface VDOM: "root"
Interface Name: port9
-- Interface Allowaccess:
-- Interface Type: physical
-- Interface IP: 0.0.0.0
-- Interface Mode: static
-- Interface VDOM: "root"
Interface Name: port10
-- Interface Allowaccess:
-- Interface Type: physical
-- Interface IP: 0.0.0.0
-- Interface Mode: static
-- Interface VDOM: "root"