We need to fetch the GTM Pool members information from the executed arbitrary bigip command. We have stored the content of the output to a register and would fetch the pool members and store it in a list.
We basically wanted to build a regular to match the output as described below.
We can try building a custom filter in python and get all the pool members.
Expected output:-
What would be the logic if there are multiple GTM pools that we need to iterate across to fetch the GTM Pool Members information?
Expected output :-
"test0506:10_10_10_2_9094, test0304:10_10_10_1_9093, abc0102:/Common/vs_10_10_10_10_80, xyz0102:/Common/vs_10_10_10_11_80, test0102:/Common/vs_10_10_10_12_80, foo0102:/Common/vs_10_10_10_13_80".
From the output as mentioned below, I need to fetch the members information and store this in a list:-
---
- hosts: gtm.abc.com
connection: local
gather_facts: no
tasks:
- name: Check Pool Contents
bigip_command:
user: admin
password: admin
server: "{{ inventory_hostname }}"
commands: "list gtm pool a {{ item }}"
warn: no
validate_certs: no
register: output
delegate_to: localhost
loop: "{{ gtm_pool }}"
- debug: var=output
The debug of output contains multiple stdout, if the list of pools contains multiple pool names.
"output": {
"changed": false,
"deprecations": [
{
"msg": "Param 'server' is deprecated. See the module docs for more information",
"version": 2.9
},
{
"msg": "Param 'user' is deprecated. See the module docs for more information",
"version": 2.9
},
{
"msg": "Param 'password' is deprecated. See the module docs for more information",
"version": 2.9
},
{
"msg": "Param 'validate_certs' is deprecated. See the module docs for more information",
"version": 2.9
},
{
"msg": "Param 'server' is deprecated. See the module docs for more information",
"version": 2.9
},
{
"msg": "Param 'user' is deprecated. See the module docs for more information",
"version": 2.9
},
{
"msg": "Param 'password' is deprecated. See the module docs for more information",
"version": 2.9
},
{
"msg": "Param 'validate_certs' is deprecated. See the module docs for more information",
"version": 2.9
}
],
"msg": "All items completed",
"results": [
{
"_ansible_delegated_vars": {
"ansible_delegated_host": "localhost",
"ansible_host": "localhost"
},
"_ansible_ignore_errors": null,
"_ansible_item_label": "test-pool1",
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": false,
"executed_commands": [
"tmsh -c \\\"list gtm pool a test-pool1\\\""
],
"failed": false,
"invocation": {
"module_args": {
"auth_provider": null,
"chdir": null,
"commands": "list gtm pool a test-pool1",
"interval": 1,
"match": "all",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"provider": {
"auth_provider": null,
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"server": "gtm.abc.com",
"server_port": null,
"ssh_keyfile": null,
"timeout": null,
"transport": "rest",
"user": "verify",
"validate_certs": false
},
"retries": 10,
"server": "gtm.abc.com",
"server_port": null,
"transport": "rest",
"user": "verify",
"validate_certs": false,
"wait_for": null,
"warn": false
}
},
"item": "test-pool1",
"stdout": [
"gtm pool a test-pool1 {\n fallback-mode drop-packet\n members {\n test0304:10_10_10_1_9093 {\n depends-on {\n test0506:10_10_10_2_9094 { }\n }\n member-order 0\n }\n }\n}"
],
"stdout_lines": [
[
"gtm pool a test-pool1 {",
" fallback-mode drop-packet",
" members {",
" test0304:10_10_10_1_9093 {",
" depends-on {",
" test0506:10_10_10_2_9094 { }",
" }",
" member-order 0",
" }",
" }",
"}"
]
]
},
{
"_ansible_delegated_vars": {
"ansible_delegated_host": "localhost",
"ansible_host": "localhost"
},
â–½ "_ansible_ignore_errors": null,
"_ansible_item_label": "test-pool2",
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": false,
"executed_commands": [
"tmsh -c \\\"list gtm pool a test-pool2\\\""
],
"failed": false,
"invocation": {
"module_args": {
"auth_provider": null,
"chdir": null,
"commands": "list gtm pool a test-pool2",
"interval": 1,
"match": "all",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"provider": {
"auth_provider": null,
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"server": "gtm.abc.com",
"server_port": null,
"ssh_keyfile": null,
"timeout": null,
"transport": "rest",
"user": "verify",
"validate_certs": false
},
"retries": 10,
"server": "gtm.abc.com",
"server_port": null,
"transport": "rest",
"user": "verify",
"validate_certs": false,
"wait_for": null,
"warn": false
}
},
"item": "test-pool2",
"stdout": [
"gtm pool a test-pool2 { alternate-mode global-availability fallback-ip 10.10.10.10 fallback-mode fallback-ip max-answers-returned 5 members { abc0102:/Common/vs_10_10_10_10_80 { disabled member-order 1 } xyz0102:/Common/vs_10_10_10_11_80 { member-order 0 } test0102:/Common/vs_10_10_10_12_80 { member-order 3 } foo0102:/Common/vs_10_10_10_13_80 { member-order 2 } } }"
],
"stdout_lines": [
[
gtm pool a test-pool2 {
alternate-mode global-availability
fallback-ip 1.1.1.1
fallback-mode fallback-ip
max-answers-returned 5
members {
abc0102:/Common/vs_10_10_10_10_80 {
disabled
member-order 1
}
xyz0102:/Common/vs_10_10_10_11_80 {
member-order 0
}
test0102:/Common/vs_10_10_10_12_80 {
member-order 3
}
foo0102:/Common/vs_10_10_10_13_80 {
member-order 2
" }",
" }",
"}"
]
]
}
]
}
}
Output Scenario 1:-
gtm pool a test-pool2 {
alternate-mode global-availability
fallback-ip 1.1.1.1
fallback-mode fallback-ip
max-answers-returned 5
members {
abc0102:/Common/vs_10_10_10_10_80 {
disabled
member-order 1
}
xyz0102:/Common/vs_10_10_10_11_80 {
member-order 0
}
test0102:/Common/vs_10_10_10_12_80 {
member-order 3
}
foo0102:/Common/vs_10_10_10_13_80 {
member-order 2
}
}
}
Output Scenario 2:-
gtm pool a test-pool1 {,
fallback-mode drop-packet",
members {",
test0304:10_10_10_1_9093 {",
depends-on {",
test0506:10_10_10_2_9094 { },
},
member-order 0",
},
},