Forum Discussion

Samir's avatar
Feb 17, 2022

Retrive the virtual server name if pool name match

Hi Expert, I am going through f5 doument, it require some changes. If there is no default pool in VIP then this pice of code will failled. Can ansible export advice me here?
  • Tsang_Han's avatar
    Feb 18, 2022

    1) The provided playbooks in works fine with the provided data and environment given in the lab exercises. They are examples provided for education and learning purpose. Exercise 1.5 playbook create all virtual servers with pool assigned. No virtual servers are created without default pool.

    2) If you have a situation and an environment that your virtual server does not have a pool assigned, the above task will fail because item.default_pool will not exists as variable/facts. You have to adapt the playbook to your situation.

    3) JRahm's suggestion of checking if the variable/facts exists is correct. However, the syntax of  item.default_pool.exists is incorrect, please refer to Search for "If a required variable has not been set, you can skip or fail using Jinja2’s defined test." in the document.

    4) The correct task syntax is show below, please note default_pool is defined as variable at the top of the playbook. This playbook has been verified to work in my own environment.



        default_pool: "/Common/http-pool"
        vip_port: 8088
      - name: Display VIP's that have a specific default pool
        debug: "msg={{}}"
          - item.default_pool is defined
          - item.default_pool == default_pool
        loop: "{{facts_result.virtual_servers}}"
              - "{{}}"
              - "{{item.default_pool | default('NO DEFAULT POOL') }}"



    5) With vip & vip1 created on a BIG-IP according to the datat given in the lab exercise and a vip-no-default-pool created manually. The above task wil have the following output.


    TASK [Display VIP's that have a specific default pool] ******************************************************************************************
    ok: [bigipa] => (item=['vip', '/Common/http-pool']) => {
        "msg": "vip"
    skipping: [bigipa] => (item=['vip-no-default-pool', 'NO DEFAULT POOL'])
    skipping: [bigipa] => (item=['vip1', '/Common/http-pool1'])