F5 Ansible使用JSON Ouptut作为Playbook中变量的输入
我正在尝试构建一个运行虚拟服务器和ltm池任务的剧本。playbook通过IP查询特定虚拟服务器的配置,并打印配置片段。其中一项是游泳池。然后,我有另一个任务,在该任务中,我试图打印与前一个任务中的虚拟服务器关联的池的配置。我正在尝试设置通过的事实,但它将poolName保留为空,因此不会返回池的配置。请帮忙 剧本:F5 Ansible使用JSON Ouptut作为Playbook中变量的输入,ansible,f5,Ansible,F5,我正在尝试构建一个运行虚拟服务器和ltm池任务的剧本。playbook通过IP查询特定虚拟服务器的配置,并打印配置片段。其中一项是游泳池。然后,我有另一个任务,在该任务中,我试图打印与前一个任务中的虚拟服务器关联的池的配置。我正在尝试设置通过的事实,但它将poolName保留为空,因此不会返回池的配置。请帮忙 剧本: --- - hosts: localhost tasks: - name: Collect VS Info bigip_device_info: gat
---
- hosts: localhost
tasks:
- name: Collect VS Info
bigip_device_info:
gather_subset:
- virtual-servers
delegate_to: localhost
register: f5virtualservers
- hosts: localhost
tasks:
- name: Collect Pool Info
bigip_device_info:
gather_subset:
- ltm-pools
delegate_to: localhost
register: f5pools
- name: Display Config for the VS selected by IP
debug:
var: item
loop: "{{ f5virtualservers | json_query(vs_ip) }}"
vars:
vs_ip: "virtual_servers[?destination_address=='{{ vsIp }}'].{name: name, pool: default_pool, availability: availability_status, IP: destination_address, Port: destination_port, Profiles: profiles[*].{name: name} Type: type Pesistence: persistence_profile}"
register: selectedvs
- set_fact:
poolName: "{{ selectedvs | json_query('virtual_servers[*].default_pool') }}"
- name: Display the pool associated with the Virtual Server
debug:
var: item
loop: "{{ f5pools | json_query(pool_name) }}"
vars:
pool_name: "ltm_pools[?full_path == '{{ poolName }}'].{name: name, Method: lb_method, Members: members[*].{name: name, state:real_state }, Monitors: monitors}"
这是“收集VS信息”的输出:
这是“收集池信息”任务的输出:
这是“IP选择的VS显示配置”任务的输出。我想从“pool”:“/Common/test”行获取信息,然后输入poolName变量:
{
"ansible_loop_var": "item",
"_ansible_no_log": false,
"item": {
"name": "www.test.com",
"IP": "1.1.1.1",
"Profiles": [
{
"name": "fastl4"
}
],
"Port": 443,
"Pesistence": "/Common/source_addr",
"Type": "standard",
"availability": "offline",
"pool": "/Common/test"
},
"changed": false,
"_ansible_verbose_always": true,
"_ansible_item_label": {
"name": "www.test.com",
"IP": "1.1.1.1",
"Profiles": [
{
"name": "fastl4"
}
],
"Port": 443,
"Pesistence": "/Common/source_addr",
"Type": "standard",
"availability": "offline",
"pool": "/Common/test"
}
}
这是“集合事实”的输出
selectedvs
将(可能)包含一个名为results
的字段,这是一个列表[dict]
,因为存在循环:
关键字;一个简单的-debug:var=selectedvs
将为您节省大量输入这个巨大问题的时间
{
"all_max_queue_entry_age_recently": 0,
"pool_queue_head_entry_age": 0,
"current_sessions": 0,
"pool_max_queue_entry_age_recently": 0,
"server_side_max_connections": 0,
"monitors": [
"/Common/tcp"
],
"available_member_count": 0,
"server_side_bits_in": 0,
"pool_max_queue_entry_age_ever": 0,
"member_count": 2,
"priority_group_activation": 0,
"allow_snat": "yes",
"reselect_tries": 0,
"enabled_status": "enabled",
"active_member_count": 0,
"server_ip_tos": "pass-through",
"server_link_qos": "pass-through",
"queue_on_connection_limit": "no",
"queue_depth_limit": 0,
"minimum_up_members_action": "failover",
"allow_nat": "yes",
"lb_method": "round-robin",
"all_avg_queue_entry_age": 0,
"ignore_persisted_weight": "no",
"server_side_bits_out": 0,
"all_num_connections_serviced": 0,
"minimum_active_members": 0,
"service_down_action": "none",
"server_side_current_connections": 0,
"members": [
{
"real_session": "monitor-enabled",
"rate_limit": "no",
"inherit_profile": "yes",
"real_state": "down",
"address": "2.2.2.1",
"logging": "no",
"monitors": [],
"ratio": 1,
"name": "2.2.2.1:443",
"partition": "Common",
"ephemeral": "no",
"connection_limit": 0,
"state": "offline",
"full_path": "/Common/2.2.2.1:443",
"fqdn_autopopulate": "no",
"priority_group": 0,
"dynamic_ratio": 1
},
{
"real_session": "monitor-enabled",
"rate_limit": "no",
"inherit_profile": "yes",
"real_state": "down",
"address": "2.2.2.2.36",
"logging": "no",
"monitors": [],
"ratio": 1,
"name": "2.2.2.2:443",
"partition": "Common",
"ephemeral": "no",
"connection_limit": 0,
"state": "offline",
"full_path": "/Common/2.2.2.2:443",
"fqdn_autopopulate": "no",
"priority_group": 0,
"dynamic_ratio": 1
}
],
"all_max_queue_entry_age_ever": 0,
"queue_time_limit": 0,
"status_reason": "The children pool member(s) are down",
"server_side_pkts_out": 0,
"server_side_total_connections": 0,
"pool_num_connections_serviced": 0,
"client_link_qos": "pass-through",
"name": "vms",
"pool_num_connections_queued_now": 0,
"minimum_up_members": 0,
"all_queue_head_entry_age": 0,
"slow_ramp_time": 10,
"server_side_pkts_in": 0,
"client_ip_tos": "pass-through",
"minimum_up_members_checking": "no",
"all_num_connections_queued_now": 0,
"availability_status": "offline",
"pool_avg_queue_entry_age": 0,
"total_requests": 0,
"full_path": "/Common/test"
}
{
"ansible_loop_var": "item",
"_ansible_no_log": false,
"item": {
"name": "www.test.com",
"IP": "1.1.1.1",
"Profiles": [
{
"name": "fastl4"
}
],
"Port": 443,
"Pesistence": "/Common/source_addr",
"Type": "standard",
"availability": "offline",
"pool": "/Common/test"
},
"changed": false,
"_ansible_verbose_always": true,
"_ansible_item_label": {
"name": "www.test.com",
"IP": "1.1.1.1",
"Profiles": [
{
"name": "fastl4"
}
],
"Port": 443,
"Pesistence": "/Common/source_addr",
"Type": "standard",
"availability": "offline",
"pool": "/Common/test"
}
}
{
"changed": false,
"ansible_facts": {
"poolName": ""
},
"_ansible_no_log": false
}