- name: Use Collections
hosts: all
connection: local
gather_facts: no
vars:
ansible_python_interpreter: /usr/local/bin/python3.9
tasks:
- name: Collect BIG-IP information
bigip_device_info:
gather_subset:
- virtual-servers
provider:
server: y.y.y.y
user: abc
password: abc1
validate_certs: False
delegate_to: localhost
register: output
- name: debug
debug: msg={{output.ansible_facts| json_query(jmesquery)}}
vars:
jmesquery: "[*].{Satus: item.availability_status, Destinationaddress: item.destination_address, Destination: item.destination}"
我得到以下输出,空消息
ansible-playbook -i inv bigipfacts.yml
PLAY [Use Collections] ***************************************************************************************************************************************************************************
TASK [Collect BIG-IP information] ****************************************************************************************************************************************************************
ok: [y.y.y.y]
TASK [debug] *************************************************************************************************************************************************************************************
ok: [y.y.y.y] => {
"msg": ""
}
PLAY RECAP ***************************************************************************************************************************************************************************************
y.y.y.y : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
必需/需要的输出-将来我想从底部输出中解析更多内容。但是现在这三个值。
"availability_status": "available",
"destination": "/1.1.1..1:8080",
"destination_address": "2.2.2.2",
"availability_status": "available",
"destination": "/3.3.3.3.3%22:8080",
"destination_address": "4.4.4.4",
output.ansible_facts具有以下信息,我想解析以下输出并仅提取如上所示的列表中的几个值
任务[调试] ************************************************** ****************************************************** ****************************************************** *************************************** 好的:[xxxx] => { “ msg”:{ “ ansible_net_queried “:true, ” ansible_net_virtual_servers“:[ { ” auto_lasthop“:”默认“, ” availability_status“:” available“, ” client_side_bits_in“:0, ” client_side_bits_out“:0, ” client_side_current_connections“:0, ” client_side_bits:evicted_connections“ “ client_side_max_connections”:0, “ client_side_pkts_in”:0,default_pool“:” / POOL01“, ”目的地“:” /1.1.1..1:8080“, “ client_side_pkts_out”:0, “ client_side_slow_killed”:0, “ client_side_total_connections”:0, “ cmp_enabled”:“是”, “ cmp_mode”:“所有CPU”, “ connection_limit”:0, “ connection_mirror_enabled”:“否”, “ cpu_usage_ratio_last_1_min”:0, “ cpu_usage_ratio_last_5_min”:0, “ cpu_usage_ratio_last_5_sec”:0, “ current_syn_cache”:0, “ default_pool”:“ / POOL01”, “ destination_address”:“ 2.2.2.2”, “ destination_port”:8080, “ enabled”:“ no”, “ephemeral_bits_in”:0, “ephemeral_bits_out”:0, “ephemeral_current_connections”:0, “ephemeral_evicted_connections”:0, “ephemeral_max_connections”:0, “ephemeral_pkts_in”:0, “ephemeral_pkts_out”:0, “ephemeral_slow_killed”:0, “ephemeral_total_connections “:0, ” full_path“:” / p1 / VS01“, ” gtm_score“:0, ” hardware_syn_cookie_instances“:0, ” max_conn_duration“:0, ” mean_conn_duration“:0, “ min_conn_duration”:0, “ name”:“ vs01”, “ nat64_enabled”:“否”, “ profiles”:[ { “ context”:“ all”, “ full_path”:“ / Common / http”, “ name”:“ http” }, { “ context”:“ all” , “ full_path”:“ / Common / oneconnect”, “ name”:“ oneconnect” }, { “ context”:“ all”, “ full_path”:“ / Common / tcp”, ” name“:” tcp“ } ], “协议”:“ tcp”, “ rate_limit”:-1, “ rate_limit_destination_mask”:0, “ rate_limit_mode”:“对象”, “ rate_limit_source_mask”:0, “ snat_type”:“自动映射”, “ software_syn_cookie_instances”:0, “ source_address“:” 0.0.0.0%22/0“, ” source_port_behavior“:”保留“, ” status_reason“:”虚拟服务器可用“, ” syn_cache_overflow“:0, ” syn_cookies_status“:“未激活”, “ total_hardware_accepted_syn_cookies”:0, “ total_hardware_syn_cookies”:0, “ total_requests”:0, “ total_software_accepted_syn_cookies”:0, “ total_software_rejected_syn_cookies”:0, “ total_software_syn_cookies”:0, “ translate_address”:“是”, “ translate_port”:“是”, “类型”:“标准”, “ vlans”:[ / / vlans “ ] }, { ” auto_lasthop“:”默认“, ” availability_status“:”可用“, ” client_side_bits_in“:0, “ client_side_evicted_connections”:0, “ client_side_bits_out”:0, “ client_side_current_connections”:0, “ client_side_max_connections”:0, “ client_side_pkts_in”:0, “ client_side_pkts_out”:0, “ client_side_slow_killed”:0, “ client_side_total_connections”:0, “ cmp_enabled”:“是”, “ cmp_mode” -cpus”, “ connection_limit”:0, “ connection_mirror_enabled”:“ no”, “ cpu_usage_ratio_last_1_min”:0, “ cpu_usage_ratio_last_5_min”:0, “ cpu_usage_ratio_last_5_sec”:0, “ current_syn_cache”:0, “ default_pool”:“ / POOL01”, “目的地”:“ /3.3.3.3.3%22:8080”, “ destination_address”:“ 4.4.4.4”, “ destination_port”:8080, “ enabled”:“ no”, “ ephemeral_bits_in”:0, “ ephemeral_bits_out”:0, “ ephemeral_current_connections”:0 , “ ephemeral_evicted_connections”:0, “ ephemeral_max_connections”:0, “ ephemeral_pkts_in”:0, “ ephemeral_pkts_out”:0, “ ephemeral_slow_killed”:0, “ephemeral_total_connections“:0, ” full_path“:” / p1 / VS01“, ” gtm_score“:0, “ hardware_syn_cookie_instances”:0, “ name”:“ oneconnect” “ max_conn_duration”:0, “ mean_conn_duration”:0, “ min_conn_duration”:0, “ name”:“ vs02”, “ nat64_enabled”:“ no”, “ profiles”:[ { “ context”:“ all”, “ full_path “:” / Common / http“, ” name“:” http“ }, { ” context“:” all“, ” full_path“:” / Common / oneconnect“, { “ context”:“ all”, }, “ full_path”:“ / Common / tcp”, “ name”:“ tcp” } ], “ protocol”:“ tcp”, “ rate_limit”:-1, “ rate_limit_destination_mask”:0, “ rate_limit_mode”:“对象“, ” rate_limit_source_mask“:0, ” snat_type“:”自动映射“, ” software_syn_cookie_instances“:0, ” source_address“:” 0.0.0.0%22/0“, ”source_port_behavior“:”保留“, ” status_reason“:”虚拟服务器可用“, “ syn_cache_overflow”:0, “ syn_cookies_status”:“未激活”, “ total_hardware_accepted_syn_cookies”:0, “ total_hardware_syn_cookies”:0, “ total_requests”:0, “ total_software_accepted_syn_cookies”:0, “ total_software_rejected_syn_cookies”:0, “ total_software_syns”: “, ” “, ” type“:” standard“, ” vlans“:[ ” / Common / vlan“ ] } ] } }
您ansible_net_virtual_servers
完全省略了它,并且似乎将JMESPath与JMESPath with_items:
(item
在jinja2中设置了一个名称)混淆,而JMESPath没有这样的隐式名称创建
- debug:
msg: >-
{{ output.ansible_facts.ansible_net_virtual_servers
| json_query(jmesquery) }}
vars:
jmesquery: "[*].{Satus: availability_status, Destinationaddress: destination_address, Destination: destination}"
产生
ok: [localhost] => {
"msg": [
{
"Destination": "/1.1.1..1:8080",
"Destinationaddress": "2.2.2.2",
"Satus": "available"
},
{
"Destination": "/3.3.3.3.3%22:8080",
"Destinationaddress": "4.4.4.4",
"Satus": "available"
}
]
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句