Forum Discussion
Ansible bigip_device_facts - Filter Output
Hi,
I'm new to ansible and have installed ansible version 2.7 and I'm trying to understand how I can filter the output from the new bigip_device_facts module as bigip_facts are depreciated.
I have checked the devcentral post for the old bigip_facts on https://devcentral.f5.com/questions/ansible-filter-output-48375
But the output from the bigip_device_facts is not the same as bigip_facts.
The new one looks like following:
changed: [172.16.223.128 -> localhost] => {
"changed": true,
"invocation": {
"module_args": {
"auth_provider": null,
"gather_subset": [
"vlans"
],
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"server": "172.16.223.128",
"server_port": 443,
"transport": null,
"user": "admin",
"validate_certs": false
}
},
"vlans": [
{
"auto_lasthop": "default",
"cmp_hash_algorithm": "default",
"failsafe_action": "failover-restart-tm",
"failsafe_enabled": "no",
"failsafe_timeout": 90,
"full_path": "/Common/HA",
"if_index": 160,
"interfaces": [
{
"full_path": "1.3",
"name": "1.3",
"tagged": "no"
}
],
"learning_mode": "enable-forward",
"mtu": 1500,
"name": "HA",
"sflow_poll_interval": 0,
"sflow_poll_interval_global": "yes",
"sflow_sampling_rate": 0,
"sflow_sampling_rate_global": "yes",
"source_check_enabled": "disabled",
"tag": 4092,
"true_mac_address": "00:0c:29:e0:10:eb"
}
]
}
Compared to the old:
"ansible_facts": {
"vlan": {
"/Common/VLAN_10": {
How can I use the debug msg to fileter and print values like vlan id (tag in this case).
Br Andréas
The result from bigip_device_facts contains a list of dictionaries. It can be processed in a number of ways depending on the output you want, but here's a simple example how to print the output with debug:
- bigip_device_facts: provider: "{{ provider_vars }}" gather_subset: - vlans register: gathered_facts - name: "Debug vlans" debug: msg: "VLAN {{ item.name }} has tag {{ item.tag }}" with_items: "{{ gathered_facts.vlans }}"
- Alex_240062Nimbostratus
The result from bigip_device_facts contains a list of dictionaries. It can be processed in a number of ways depending on the output you want, but here's a simple example how to print the output with debug:
- bigip_device_facts: provider: "{{ provider_vars }}" gather_subset: - vlans register: gathered_facts - name: "Debug vlans" debug: msg: "VLAN {{ item.name }} has tag {{ item.tag }}" with_items: "{{ gathered_facts.vlans }}"
- jmartinez_38641Nimbostratus
Hi all,
I came here with the same doubt. the answer given is good and works perfectly, but if the gather_subset item contains a special character, it doesn't work.
This produces an error:
- bigip_device_facts: provider: "{{ provider_vars }}" gather_subset: - ltm-pools register: gathered_facts - name: "Debug vlans" debug: msg: "VLAN {{ item.name }} has tag {{ item.tag }}" with_items: "{{ gathered_facts.ltm-pools }}"
Output error:
FAILED! => {"msg": "Unable to look up a name or access an attribute in template string ({{ bigip_device_facts.ltm-pools }}).\nMake sure your variable name does not contain invalid characters like '-': unsupported operand type(s) for -: 'StrictUndefined' and 'AnsibleUnicode'"} to retry, use: --limit @/opt/project/facts.retry
Any ideas? Thanks.
- Vladimir_Bojko1Historic F5 Account
I think your error is: gathered_facts.ltm_pools instead of gathered_facts.ltm-pools
- jmartinez_38641Nimbostratus
Hi,
It was my fault. I was using as variable the 'ltm-pool' option from gather_subset instead of the 'ltm_pool' from the output of the registered facts. It works as expected.
Thanks!
- jmartinez_38641Nimbostratus
Hi all, I am having another issue obtaining filtered information from this module. With the given example, I can use the item.* for referencing the subfields under 'vlans'.
"bigip_device_facts": { "changed": true, "failed": false, "vlans": [ { "auto_lasthop": "default", "cmp_hash_algorithm": "default", "failsafe_action": "failover-restart-tm", "failsafe_enabled": "no", "failsafe_timeout": 90, "full_path": "/Common/F5TEST", "if_index": 96, "learning_mode": "enable-forward", "mtu": 1500, "name": "F5TEST", "sflow_poll_interval": 0, "sflow_poll_interval_global": "yes", "sflow_sampling_rate": 0, "sflow_sampling_rate_global": "yes", "source_check_enabled": "disabled", "tag": 2015, "true_mac_address": "00:11:22:33:44:55"
But, if I use the subset 'ltm-pools', there is another sublevel under members.
"bigip_device_facts": { "changed": true, "failed": false, "ltm_pools": [ { "allow_nat": "yes", "allow_snat": "yes", "client_ip_tos": "pass-through", "client_link_qos": "pass-through", "full_path": "/Common/mypool", "ignore_persisted_weight": "no", "lb_method": "round-robin", "members": [ { "address": "192.168.10.10", "connection_limit": 0, "dynamic_ratio": 1, "ephemeral": "no", "fqdn_autopopulate": "no", "full_path": "/Common/myhost:8080", "inherit_profile": "yes", "logging": "no", "monitors": [], "name": "myhost:8080", "partition": "Common", "priority_group": 0, "rate_limit": "no", "ratio": 1, "state": "disabled" },
I want to extract only 'name' and 'state', but it remains in the previous level.
- name: "LTM_POOLS OUTPUT" debug: msg: "{{ item.members }} has name {{ item.name }} and state {{ item.state }}" with_items: "{{ bigip_device_facts.ltm_pools }}" when: item.full_path == "/Common/mypool"
This doesn't work. It remains at member level. How can I reference the sublevel of members? Thanks!
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