fortios_json_generic – Configure Fortinet’s FortiOS and FortiGate with json generic method.

Synopsis

This module is able to configure a FortiGate or FortiOS (FOS) device by allowing the user to set any category supported by FortiAPI with raw json. All parameters and values included in examples need to be adjusted to datasources before usage.

Requirements

The below requirements are needed on the host that executes this module.

  • install galaxy collection fortinet.fortios >= 2.0.0

Parameters

  • vdom - Virtual domain, among those defined previously. A vdom is a virtual instance of the FortiGate that can be configured and used as a different unit. type: str default: root
  • enable_log - Enable/Disable logging for task. type: bool required: False default: False
  • access_token - Token-based authentication. Generated from GUI of Fortigate. type: str required: False
  • json_generic - json generic default: null type: dict
    • dictbody - Body with YAML list of key/value format type: dict
    • jsonbody - Body with JSON string format, will always give priority to jsonbody type: str
    • method - HTTP methods type: str choices: GET, PUT, POST, DELETE
    • path - URL path, e.g./api/v2/cmdb/firewall/address type: str
    • specialparams - Extra URL parameters, e.g.start=1&count=10 type: str

Examples

host

[fortigates]
fortigate01 ansible_host=192.168.52.177 ansible_user="admin" ansible_password="admin"

[fortigates:vars]
ansible_network_os=fortios

sample1.yml

---
- hosts: fortigates
  connection: httpapi
  collections:
    - fortinet.fortios
  vars:
   vdom: "root"
   ansible_httpapi_use_ssl: yes
   ansible_httpapi_validate_certs: no
   ansible_httpapi_port: 443

  tasks:
  - name: test add with string
    fortios_json_generic:
      vdom:  "{{ vdom }}"
      json_generic:
        method: "POST"
        path: "/api/v2/cmdb/firewall/address"
        jsonbody: |
          {
          "name": "111",
          "type": "geography",
          "fqdn": "",
          "country": "AL",
          "comment": "ccc",
          "visibility": "enable",
          "associated-interface": "port1",
          "allow-routing": "disable"
          }
    register: info

  - name: display vars
    debug: msg="{{info}}"

sample2.yml

---
- hosts: fortigates
  connection: httpapi
  collections:
    - fortinet.fortios
  vars:
   vdom: "root"
   ansible_httpapi_use_ssl: yes
   ansible_httpapi_validate_certs: no
   ansible_httpapi_port: 443

  tasks:
  - name: test delete
    fortios_json_generic:
      vdom:  "{{ vdom }}"
      json_generic:
        method: "DELETE"
        path: "/api/v2/cmdb/firewall/address/111"
        specialparams: "testpara1=1&testpara2=2"
    register: info

  - name: display vars
    debug: msg="{{info}}"

  - name: test add with dict
    fortios_json_generic:
      vdom:  "{{ vdom }}"
      json_generic:
        method: "POST"
        path: "/api/v2/cmdb/firewall/address"
        dictbody:
          name: "111"
          type: "geography"
          fqdn: ""
          country: "AL"
          comment: "ccc"
          visibility: "enable"
          associated-interface: "port1"
          allow-routing: "disable"
    register: info

  - name: display vars
    debug: msg="{{info}}"

  - name: test delete
    fortios_json_generic:
      vdom:  "{{ vdom }}"
      json_generic:
        method: "DELETE"
        path: "/api/v2/cmdb/firewall/address/111"
    register: info

  - name: display vars
    debug: msg="{{info}}"

  - name: test add with string
    fortios_json_generic:
      vdom:  "{{ vdom }}"
      json_generic:
        method: "POST"
        path: "/api/v2/cmdb/firewall/address"
        jsonbody: |
          {
          "name": "111",
          "type": "geography",
          "fqdn": "",
          "country": "AL",
          "comment": "ccc",
          "visibility": "enable",
          "associated-interface": "port1",
          "allow-routing": "disable"
          }
    register: info

  - name: display vars
    debug: msg="{{info}}"

sample3.yml

---
- hosts: fortigates
  collections:
    - fortinet.fortios
  connection: httpapi
  vars:
   vdom: "root"
   ansible_httpapi_use_ssl: yes
   ansible_httpapi_validate_certs: no
   ansible_httpapi_port: 443

  tasks:
  - name: test firewall policy order modification
    fortios_json_generic:
      vdom:  "{{ vdom }}"
      json_generic:
            method: "PUT"
            path: "/api/v2/cmdb/firewall/policy/1"
            specialparams: "action=move&after=2"
    register: info

  - name: display vars
    debug: msg="{{info}}"

Return Values

Common return values are documented: https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values, the following are the fields unique to this module:

  • build - Build number of the fortigate image returned: always type: str sample: '1547'
  • http_method - Last method used to provision the content into FortiGate returned: always type: str sample: 'PUT'
  • http_status - Last result given by FortiGate on last operation applied returned: always type: str sample: 200
  • mkey - Master key (id) used in the last call to FortiGate returned: success type: str sample: id
  • name - Name of the table used to fulfill the request returned: always type: str sample: urlfilter
  • path - Path of the table used to fulfill the request returned: always type: str sample: webfilter
  • revision - Internal revision number returned: always type: str sample: 17.0.2.10658
  • serial - Serial number of the unit returned: always type: str sample: FGVMEVYYQT3AB5352
  • status - Indication of the operation's result returned: always type: str sample: success
  • vdom - Virtual domain used returned: always type: str sample: root
  • version - Version of the FortiGate returned: always type: str sample: v5.6.3

Authors

  • Link Zheng (@chillancezen)
  • Jie Xue (@JieX19)
  • Frank Shen (@fshen01)
  • Hongbin Lu (@fgtdev-hblu)

Warning

It’s preferred to use FortiOS Ansible Collection Included Modules unless some features are not available there.