cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.

Retrive the virtual server name if pool name match

Samir
Nacreous
Nacreous

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?

https://clouddocs.f5.com/training/fas-ansible-workshop-101/1.8-virtual-server-facts.html#solution

- name: Display VIP's that have a specific default pool
  debug: "msg={{item.name}}"
  when: item.default_pool == dA_pool
  loop: "{{facts_result.virtual_servers}}"
  loop_control:
        label:
        - "{{item.name}}"
        - "{{item.default_pool}}"

 

1 ACCEPTED SOLUTION

Tsang_Han
F5 Employee
F5 Employee

1) The provided playbooks in https://clouddocs.f5.com/training/fas-ansible-workshop-101/ 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 https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html. 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.

 

 

.
.
.
  vars:
    default_pool: "/Common/http-pool"
    vip_port: 8088
.
.
.
  - name: Display VIP's that have a specific default pool
    debug: "msg={{item.name}}"
    when:
      - item.default_pool is defined
      - item.default_pool == default_pool
    loop: "{{facts_result.virtual_servers}}"
    loop_control:
          label:
          - "{{item.name}}"
          - "{{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'])

 

 


View solution in original post

4 REPLIES 4

JRahm
Community Manager
Community Manager

Have you tried a conditional on that when statement?

when:
- item.default_pool.exists
- item.default_pool == dA_pool

 

Tsang_Han
F5 Employee
F5 Employee

1) The provided playbooks in https://clouddocs.f5.com/training/fas-ansible-workshop-101/ 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 https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html. 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.

 

 

.
.
.
  vars:
    default_pool: "/Common/http-pool"
    vip_port: 8088
.
.
.
  - name: Display VIP's that have a specific default pool
    debug: "msg={{item.name}}"
    when:
      - item.default_pool is defined
      - item.default_pool == default_pool
    loop: "{{facts_result.virtual_servers}}"
    loop_control:
          label:
          - "{{item.name}}"
          - "{{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'])

 

 


JRahm
Community Manager
Community Manager

Doh, so close...thanks @Tsang_Han for picking up my slack! 🙂

Samir
Nacreous
Nacreous

thank you so much for giving hints. can we add some loop place of default_pool? appreciate your hints

 

- item.default_pool ==default_pool