过滤 Ansible 输出以获得特定结果

Filtering Ansible Output to get specific result

我有以下 ansible 剧本,用于从 NAT 规则中收集事实。该剧本按预期工作:

- name: Get Facts from NAT Rules
  hosts: panorama
  connection:  local
  gather_facts:  False
  vars:
    ansible_python_interpreter: /usr/bin/python3
    
  
  collections:
    - paloaltonetworks.panos

  tasks:
    - name: Get a list of all NAT rules
      panos_nat_rule_facts:
        provider: '{{ provider }}'
        listing: True 
        device_group: PA-02
        rulebase: post-rulebase
      register: nat_rules 

    - debug:
        msg: '{{ nat_rules.listing }}'

剧本的输出提供了 NAT 规则的事实,但是,我只想获得 snat_static_address 的值,而不是其他任何东西:

ok: [10.1.10.100] => {
    "msg": [
        {
            "description": null,
            "destination_dynamic_translated_address": null,
            "destination_dynamic_translated_distribution": null,
            "destination_dynamic_translated_port": null,
            "destination_ip": [
                "any"
            ],
            "destination_zone": [
                "wan"
            ],
            "disabled": null,
            "dnat_address": null,
            "dnat_port": null,
            "group_tag": null,
            "ha_binding": null,
            "nat_type": null,
            "negate_target": false,
            "rule_name": "NAT_01",
            "service": "any",
            "snat_address_type": null,
            "snat_bidirectional": true,
            "snat_dynamic_address": null,
            "snat_interface": null,
            "snat_interface_address": null,
            "snat_static_address": "74.120.99.147",
            "snat_type": "static-ip",
            "source_ip": [
                "10.1.10.10"
            ],
            "source_translation_fallback_interface": null,
            "source_translation_fallback_ip_address": null,
            "source_translation_fallback_ip_type": null,
            "source_translation_fallback_translated_addresses": null,
            "source_translation_fallback_type": null,
            "source_zone": [
                "lan"
            ],
            "tag_val": null,
            "target": null,
            "to_interface": null,
            "uuid": null
        }
    ]
}

我想过滤此输出以检索值:snat_static_address。 我怎样才能做到这一点?

您可以使用以下语法引用该值

- debug:
    msg: '{{ nat_rules.listing | map(attribute="snat_static_address") }}'