Tuesday, 26 March 2019

Ansible playbook to add and delete static route on fortigate firewall



---
 - name: modifyRoutes
   gather_facts: no
   connection: local
   hosts: FORTINET
 
   vars:
     action: StaticRouteAddition
     vdom: root
     interfacename: ['interface port-channel 35.3102']
     interfacename2: port-channel 35.3102
     ip: 192.168.101.101
     mask: 255.255.255.0
     speedmode: auto
     duplexmode: auto
     securityinterfacename: inside
     securitylevelnumber: 0
     devicetype: FORTINET
     routeModificationType: addition
     routeMode:
     hostIPAddress: 192.168.101.101
     hostIPMask: 255.255.255.0
     nextHopIP: 192.168.102.102
     adminDistance: 10
     destIPAddress:
     destIPMask:
     destGatewayIPAddress:
     distanceValue:
     comments:
     portNum:

     cli:
      host:
      username:
      password:
      auth_pass:
      authorize: yes
      timeout: 100

   tasks:

    - name: StaticRouteAddition
      when: action == "StaticRouteAddition" and devicetype == "FORTINET"
      fortios_config:
         vdom: "{{vdomname}}"
         commands:
            - config router static
            - "edit {{portNum}}"
            - "set dst {{$destIPAddress}}"
            - "set gateway {{destGatewayIPAddress}}"
            - "set device {{interfacename2}}"
            - "set comment {{comment}}"
         provider: "{{ cli }}"


    - name: StaticRouteDeletion
      when: action == "StaticRouteDeletion" and devicetype == "FORTINET"
      fortios_config:
         vdom: "{{vdomname}}"
         commands:
            - config router static
            - "edit {{portNum}}"
            - "set dst {{$destIPAddress}}"
            - "set gateway {{destGatewayIPAddress}}"
            - "set device {{interfacename2}}"
            - "set comment {{comment}}"
         provider: "{{ cli }}"

No comments:

Post a Comment

Git

1 git add ↳ It lets you add changes from the working directory into the staging area 2 git commit ↳ It lets you save a snapshot of currently...