Forum Discussion
Retrive the virtual server name if pool name match
- Feb 18, 2022
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'])
Have you tried a conditional on that when statement?
when:
- item.default_pool.exists
- item.default_pool == dA_pool
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com