Configuring Ansible for Avi Vantage

Support for Ansible Collections

Starting with Avi Vantage release 21.1.1, the support for Ansible collection is available for Avi Vantage deployments. The Ansible collections are supported for Ansible version 2.9.10 or the later versions. The detailed information about installation and usage is available at`at Advanced Load Balancer (formerly Avi) Ansible Collection.

Installing and Using Ansible Collections

Ansible needs to be installed

  1. To install the Ansible, use the following commands:

    
    pip install ansible
    
  2. Use the following command to Install the collection:

    
    ansible-galaxy collection install vmware.alb
    

Usage

Using External Credentials or Variable File while Using ALB Module
Following is the creds.yml file for using external credentials or variable file.


  avi_credentials:
      controller: "192.168.1.11"
      username: "admin"
      password: "password"
      api_version: "22.2.1"
      tenant: "admin"
  

Creating Configuration Using ALB Ansible Modules
Use the following create_config.yml to create configuration using the ALB Ansible modules.


  - hosts: localhost
    connection: local
    collections:
      - vmware.alb
    vars_files:
      - creds.yml
    tasks:
      - name: Example to create a Health Montor object
        avi_healthmonitor:
          avi_credentials: ""
          name: http
          receive_timeout: 4
          failed_checks: 3
          send_interval: 5
          successful_checks: 1
          type: HEALTH_MONITOR_HTTP
          http_monitor:
            exact_http_request: true
            http_request: GET / HTTP/1.1\r\n
            http_response_code:
              - HTTP_2XX
              - HTTP_3XX
            http_response: ''
      - name: Example to create a Pool object
        avi_pool:
          avi_credentials: ""
          name: pool
          description: null
          servers:
            - ip:
              addr: 192.168.12.15
              type: V4
            enabled: true
            description: ''
            port: '80'
          - ip:
              addr: 192.168.12.16
              type: V4
            enabled: true
            description: ''
            port: '80'
        fail_action:
          type: FAIL_ACTION_CLOSE_CONN
        lb_algorithm: LB_ALGORITHM_ROUND_ROBIN
        cloud_ref: "/api/cloud?name=Default-Cloud"
        health_monitor_refs:
          - "/api/healthmonitor?name=http"
    - name: Example to create a VsVip object
      avi_vsvip:
        avi_credentials: ""
        name: vsvip
        cloud_ref: "/api/cloud/?name=Default-Cloud"
        vip:
          - ip_address:
              type: V4
              addr: 10.10.26.28
            vip_id: '0'
    - name: Example to create a Virtual Service object
      avi_virtualservice:
        avi_credentials: ""
        name: test_vs
        enabled: true
        services:
          - enable_ssl: true
            port: 3000
        type: "VS_TYPE_NORMAL"
        vsvip_ref: "/api/vsvip/?name=vsvip"
        cloud_ref: "/api/cloud?name=Default-Cloud"
        pool_ref: "/api/pool/?tenant=admin&name=pool&cloud=Default-Cloud"

Deleting Configuration Using ALB Ansible Modules
Use the following delete_config.yml to delete configuration using ALB Ansible modules.


- hosts: localhost
  connection: local
  collections:
    - vmware.alb
  vars_files:
    - creds.yml
  tasks:
    - name: Example to delete a Virtual Service object
      avi_virtualservice: # and order should be reverse
        avi_credentials: ""
        state: absent # this change we need to do
        name: test_vs
        enabled: true
        services:
          - enable_ssl: true
            port: 3000
        type: "VS_TYPE_NORMAL"
        vsvip_ref: "/api/vsvip/?name=vsvip"
        cloud_ref: "/api/cloud?name=Default-Cloud"
        pool_ref: "/api/pool/?tenant=admin&name=pool&cloud=Default-Cloud"
    - name: Example to delete a VsVip object
      avi_vsvip:
        avi_credentials: ""
        state: absent 
        name: vsvip
        cloud_ref: "/api/cloud/?name=Default-Cloud"
        vip:
          - ip_address:
              type: V4
              addr: 10.10.26.28
            vip_id: '0'
    - name: Example to delete a Pool object
      avi_pool:
        avi_credentials: ""
        state: absent
        name: pool
        description: null
        servers:
          - ip:
              addr: 192.168.12.15
              type: V4
            enabled: true
            description: ''
            port: '80'
          - ip:
              addr: 192.168.12.16
              type: V4
            enabled: true
            description: ''
            port: '80'
        fail_action:
          type: FAIL_ACTION_CLOSE_CONN
        lb_algorithm: LB_ALGORITHM_ROUND_ROBIN
        cloud_ref: "/api/cloud?name=Default-Cloud"
        health_monitor_refs:
          - "/api/healthmonitor?name=http"
    - name: Example to delete a Health Montor object
      avi_healthmonitor:
        avi_credentials: ""
        state: absent
        name: http
        receive_timeout: 4
        failed_checks: 3
        send_interval: 5
        successful_checks: 1
        type: HEALTH_MONITOR_HTTP
        http_monitor:
          exact_http_request: true
          http_request: GET / HTTP/1.1\r\n
          http_response_code:
            - HTTP_2XX
            - HTTP_3XX
          http_response: ''

Creating/Deleting Configuration Using aviconfig Role
Use the following config.yml and **main.yml to create or delete configuration using the aviconfig role.


  avi_config:
   healthmonitor:
    - tenant_ref: "/api/tenant/?name=admin"
      name: http
      receive_timeout: 4
      failed_checks: 3
      send_interval: 5
      successful_checks: 1
      type: HEALTH_MONITOR_HTTP
      http_monitor:
        exact_http_request: true
        http_request: GET / HTTP/1.1\r\n
        http_response_code:
          - HTTP_2XX
          - HTTP_3XX
        http_response: ''
   pool:
    - name: pool
      description: null
      servers:
        - ip:
            addr: 192.168.12.15
            type: V4
          enabled: true
          description: ''
          port: '80'
        - ip:
            addr: 192.168.12.16
            type: V4
          enabled: true
          description: ''
          port: '80'
      fail_action:
        type: FAIL_ACTION_CLOSE_CONN
      lb_algorithm: LB_ALGORITHM_ROUND_ROBIN
      cloud_ref: "/api/cloud?name=Default-Cloud"
      health_monitor_refs:
        - "/api/healthmonitor?name=http"
  vsvip:
    - name: vsvip
      cloud_ref: "/api/cloud/?name=Default-Cloud"
      vip:
        - ip_address:
            type: V4
            addr: 10.10.26.28
          vip_id: '0'
  virtualservice:
    - name: test-vs
      enabled: true
      services:
        - enable_ssl: true
          port: 3000
      type: "VS_TYPE_NORMAL"
      vsvip_ref: "/api/vsvip/?name=vsvip"
      cloud_ref: "/api/cloud?name=Default-Cloud"
      pool_ref: "/api/pool/?tenant=admin&name=pool&cloud=Default-Cloud"

main.yml


- hosts: localhost
  connection: local
  collections:
    - vmware.alb
  tasks:
    - name: Create pool using aviconfig role
      import_role:
        name: aviconfig
      vars:
          avi_config_file: "config.yml"
          avi_creds_file: "creds.yml"
          avi_config_state: present # Change this to absent to delete config
          # avi_creds_file parameter is only valid for aviconfig role.
          # For importing credentials from external file in modules,
          # please use vars_files parameter as shown in previous example if using reguler modules
  

Additional References