Skip to content

Creating an HTTP Virtual Server

erjac77 edited this page Jun 29, 2018 · 3 revisions
- name: Configure an HTTP virtual server
  hosts: bigips
  connection: local
  roles:
    - erjac77.module-f5bigip
  vars:
    http_user: admin
    http_pass: admin
    http_port: 443
    bigip_partition: Common
    pool_name: my_pool
    pool_description: My pool
    pool_load_balancing_mode: least-connections-member
    pool_members:
      - { name: my_member_1, address: 10.10.10.101, port: 80, description: My member 1, ratio: 2 }
      - { name: my_member_2, address: 10.10.10.102, port: 80, description: My member 2, ratio: 1 }
    virtual_name: my_http_vs
    virtual_description: My http vs
    virtual_destination: "/{{ bigip_partition }}/10.10.20.201:80"
    virtual_ip_protocol: tcp
    virtual_pool: "/{{ bigip_partition }}/{{ pool_name }}"
    virtual_sat: {
      type: automap
    }
    virtual_vlans:
      - "/{{ bigip_partition }}/external"
    virtual_vlans_enabled: true
    virtual_profiles:
      - { name: tcp, partition: Common, context: all }
      - { name: http, partition: Common, context: all }
      - { name: oneconnect, partition: Common, context: all }
    virtual_persists:
      - { name: 'cookie', partition: Common, tmDefault: 'yes' }
    virtual_fallback_persistence: '/Common/source_addr'

  tasks:

    - name: Create a pool
      f5bigip_ltm_pool:
        f5_hostname: "{{ inventory_hostname }}"
        f5_username: "{{ http_user }}"
        f5_password: "{{ http_pass }}"
        f5_port: "{{ http_port }}"
        name: "{{ pool_name }}"
        partition: "{{ bigip_partition }}"
        description: "{{ pool_description }}"
        load_balancing_mode: "{{ pool_load_balancing_mode }}"
        state: present

    - name: Add members to the pool
      f5bigip_ltm_pool_member:
        f5_hostname: "{{ inventory_hostname }}"
        f5_username: "{{ http_user }}"
        f5_password: "{{ http_pass }}"
        f5_port: "{{ http_port }}"
        name: "{{ item.name }}:{{ item.port }}"
        partition: "{{ bigip_partition }}"
        description: "{{ item.description }}"
        address: "{{ item.address }}"
        pool: "{{ pool_name }}"
        state: present
      with_items: "{{ pool_members }}"

    - name: Create a virtual server
      f5bigip_ltm_virtual:
        f5_hostname: "{{ inventory_hostname }}"
        f5_username: "{{ http_user }}"
        f5_password: "{{ http_pass }}"
        f5_port: "{{ http_port }}"
        name: "{{ virtual_name }}"
        partition: "{{ bigip_partition }}"
        description: "{{ virtual_description }}"
        destination: "{{ virtual_destination }}"
        ip_protocol: "{{ virtual_ip_protocol }}"
        pool: "{{ virtual_pool }}"
        source_address_translation: "{{ virtual_sat }}"
        vlans: "{{ virtual_vlans }}"
        vlans_enabled: "{{ virtual_vlans_enabled }}"
        state: present

    - name: Add profiles to the virtual server
      f5bigip_ltm_virtual_profile:
        f5_hostname: "{{ inventory_hostname }}"
        f5_username: "{{ http_user }}"
        f5_password: "{{ http_pass }}"
        f5_port: "{{ http_port }}"
        name: "{{ item.name }}"
        partition: "{{ bigip_partition }}"
        context: "{{ item.context }}"
        virtual: "/{{ bigip_partition }}/{{ virtual_name }}"
        state: present
      with_items: "{{ virtual_profiles }}"

    - name: Add persistence to the virtual server
      f5bigip_ltm_virtual:
        f5_hostname: "{{ inventory_hostname }}"
        f5_username: "{{ http_user }}"
        f5_password: "{{ http_pass }}"
        f5_port: "{{ http_port }}"
        name: "{{ virtual_name }}"
        partition: "{{ bigip_partition }}"
        persist: "{{ virtual_persists }}"
        fallback_persistence: "{{ virtual_fallback_persistence }}"
        state: present
Clone this wiki locally