fortinet.fortios.fortios_json_generic 模块 – 使用 JSON 通用方法配置 Fortinet 的 FortiOS 和 FortiGate。

注意

此模块是 fortinet.fortios 集合 (版本 2.3.8) 的一部分。

如果您使用的是 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install fortinet.fortios。您需要满足其他要求才能使用此模块,请参阅 需求 以了解详情。

要在剧本中使用它,请指定:fortinet.fortios.fortios_json_generic

fortinet.fortios 2.0.0 中的新增功能

概要

  • 此模块能够通过允许用户设置和修改 JSON 功能和通用类别来配置 FortiGate 或 FortiOS (FOS) 设备。示例包括所有参数,在使用前需要将值调整到数据源。已在 FOS v6.0.4 上测试。

需求

执行此模块的主机需要以下需求。

  • fortiosapi>=0.9.8

参数

参数

注释

access_token

字符串

基于令牌的身份验证。从 FortiGate 的 GUI 生成。

enable_log

布尔值

启用/禁用任务的日志记录。

选项

  • false ← (默认)

  • true

json_generic

字典

JSON 通用

dictbody

字典

使用 YAML 键/值格式列表的正文

jsonbody

字符串

使用 JSON 字符串格式的正文,将始终优先于 jsonbody

method

字符串 / 必填

HTTP 方法

选项

  • "GET"

  • "PUT"

  • "POST"

  • "DELETE"

path

字符串 / 必填

URL 路径,例如 /api/v2/cmdb/firewall/address

specialparams

字符串

额外的 URL 参数,例如 start=1&count=10

vdom

字符串

虚拟域,在先前定义的虚拟域中。vdom 是 FortiGate 的虚拟实例,可以将其配置并用作不同的单元。

默认值: "root"

注释

注意

  • 需要 Fortinet 开发的 fortiosapi 库

  • 在您的剧本中作为 local_action 运行

示例

- name: add firewall address
  fortinet.fortios.fortios_json_generic:
      vdom: "root"
      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}}"

- name: delete firewall address
  fortinet.fortios.fortios_json_generic:
      vdom: "root"
      json_generic:
          method: "DELETE"
          path: "/api/v2/cmdb/firewall/address/111"
  register: info

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

- name: test add with dict
  fortinet.fortios.fortios_json_generic:
      vdom: "root"
      json_generic:
          method: "POST"
          path: "/api/v2/cmdb/firewall/address"
          dictbody:
              name: "111"
              type: "geography"
              fqdn: ""
              country: "AL"
              comment: "it's a test"
              visibility: "enable"
              associated-interface: "port1"
              allow-routing: "disable"
  register: info

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

- name: test speical params
  fortinet.fortios.fortios_json_generic:
      vdom: "root"
      json_generic:
          method: "PUT"
          path: "/api/v2/cmdb/firewall/policy/1"
          specialparams: "action=move&after=2"
  register: info

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

返回值

常用的返回值已在此处记录 此处,以下是此模块独有的字段

描述

build

字符串

FortiGate 镜像的版本号

返回: 始终

示例: "1547"

http_method

字符串

上次用于将内容置备到 FortiGate 的方法

返回: 始终

示例: "PUT"

http_status

字符串

FortiGate 在上次应用的操作中给出的最后结果

返回: 始终

示例: "200"

mkey

字符串

上次调用 FortiGate 时使用的主密钥 (ID)

返回: 成功

示例: "id"

name

字符串

用于完成请求的表的名称

返回: 始终

示例: "urlfilter"

path

字符串

path

返回: 始终

用于完成请求的表的路径

示例: "webfilter"

字符串

revision

返回: 始终

内部修订号

示例: "17.0.2.10658"

字符串

serial

返回: 始终

设备的序列号

示例: "FGVMEVYYQT3AB5352"

字符串

status

返回: 始终

操作结果的指示

vdom

字符串

示例: "success"

返回: 始终

vdom

使用的虚拟域

字符串

示例: "root"

返回: 始终

version

作者

  • Frank Shen (@frankshen01)

  • 卢洪斌 (@fgtdev-hblu)