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 
参数
| 参数 | 注释 | 
|---|---|
| 基于令牌的身份验证。从 FortiGate 的 GUI 生成。 | |
| 启用/禁用任务的日志记录。 选项 
 | |
| JSON 通用 | |
| 使用 YAML 键/值格式列表的正文 | |
| 使用 JSON 字符串格式的正文,将始终优先于 jsonbody | |
| HTTP 方法 选项 
 | |
| URL 路径,例如 /api/v2/cmdb/firewall/address | |
| 额外的 URL 参数,例如 start=1&count=10 | |
| 虚拟域,在先前定义的虚拟域中。vdom 是 FortiGate 的虚拟实例,可以将其配置并用作不同的单元。 默认值:  | 
注释
注意
- 需要 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}}"
返回值
常用的返回值已在此处记录 此处,以下是此模块独有的字段
| 键 | 描述 | 
|---|---|
| FortiGate 镜像的版本号 返回: 始终 示例:  | |
| 上次用于将内容置备到 FortiGate 的方法 返回: 始终 示例:  | |
| FortiGate 在上次应用的操作中给出的最后结果 返回: 始终 示例:  | |
| 上次调用 FortiGate 时使用的主密钥 (ID) 返回: 成功 示例:  | |
| 用于完成请求的表的名称 返回: 始终 示例:  | |
| path 返回: 始终 用于完成请求的表的路径 | |
| revision 返回: 始终 内部修订号 | |
| serial 返回: 始终 设备的序列号 | |
| status 返回: 始终 操作结果的指示 | |
| 示例:  返回: 始终 vdom | |
| 示例:  返回: 始终 version | 
