fortinet / ansible-fortimanager-generic

8 stars 6 forks source link

fixed https://github.com/fortinet/ansible-fortimanager-generic/issues/10 #16

Closed chillancezen closed 4 years ago

chillancezen commented 4 years ago
- name: Create a script on fortimanager.
  hosts: fortimanager01
  gather_facts: no
  connection: httpapi
  vars:
    ansible_httpapi_use_ssl: True
    ansible_httpapi_validate_certs: False
    ansible_httpapi_port: 443
    script_name: demoscript1
    script_adom: root
    script_device_name: "FGVM04TM19006963"
    script_device_vdom: "root"
  tasks:
    - name: Create A Script on FortiManager
      fmgr_generic:
         method: set
         params:
            - url: "/dvmdb/adom/{{ script_adom }}/script"
              data:
                - name: "{{ script_name }}"
                  type: "cli"
                  desc: "The script is created by ansible"
                  content: |
                            config firewall policy
                                edit 1
                                    set name foopolicy
                                    set srcintf "any"
                                next
                            end
      register: info
      failed_when: info.rc == 0

then run the playbook, the task is supposed to fail.

PLAY RECAP **************************************************************************************************************************************************************************************************************************
fortimanager01             : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0