Tuesday, 26 March 2019

ansible playbook to mange cisco ASA Interface



---
 - name: ASAInterfaceManagement
   gather_facts: no
   connection: local
   hosts: ASA
 
   vars:
     action: showVersion1
     contextname: fw-automation-test
     interfacename: ['interface port-channel 35.3102']
     ip:
     mask:
     speedmode: auto
     duplexmode: auto
     securityinterfacename: inside
     securitylevelnumber: 0
     devicetype: fortigate
     cli:
      host:
      username:
      password:
      auth_pass:
      timeout: 30

   tasks:
    - name: show version
      when: action == "showVersion" and devicetype == "ciscoASA"
      asa_command:
         commands:
            - show version
         provider: "{{ cli }}"
     
    - name: enable interface
      when: action == "enableInterface" and devicetype == "ciscoASA"
      asa_config:
         context: "{{contextname}}"
         commands:
            - no shut
         parents: "{{interfacename}}"
         provider: "{{ cli }}"


    - name: disable interface
      when: action == "disableInterface" and devicetype == "ciscoASA"
      asa_config:
         context: "{{contextname}}"
         commands:
            - shut
         parents: "{{interfacename}}"
         provider: "{{ cli }}"

    - name: setIPAddress
      when: action == "setIPAddress" and devicetype == "ciscoASA"
      asa_config:
         context: "{{contextname}}"
         commands:
            - "ip address {{ip}} {{mask}}"
            - no shut
         parents: "{{interfacename}}"
         provider: "{{ cli }}"

    - name: unsetIPAddress
      when: action == "unsetIPAddress" and devicetype == "ciscoASA"
      asa_config:
         context: "{{contextname}}"
         commands:
            - no ip address
         parents: "{{interfacename}}"
         provider: "{{ cli }}"

    - name: setSpeed
      when: action == "setSpeed" and devicetype == "ciscoASA"
      asa_config:
         context: "{{contextname}}"
         commands:
             - speed "{{speedmode}}"
         parents: "{{interfacename}}"
         provider: "{{ cli }}"

    - name: setDuplex
      when: action == "setDuplex" and devicetype == "ciscoASA"
      asa_config:
         context: "{{contextname}}"
         commands:
             - speed "{{duplexmode}}"
         parents: "{{interfacename}}"
         provider: "{{ cli }}"

    - name: setSecurityLevel
      when: action == "setSecurityLevel" and devicetype == "ciscoASA"
      asa_config:
         context: "{{contextname}}"
         commands:
             - nameif "{{securityinterfacename}}"
             - security-level "{{securitylevelnumber}}"
         parents: "{{interfacename}}"
         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...