确保过滤器在playbook中正确设置,并通过将setup输出的变量存储在变量中来使用它们。以下是示例:
playbook.yml文件:
- hosts: all
gather_facts: yes
tasks:
- name: Use setup module and filter
setup:
register: setup_output
- debug:
var: setup_output | json_query('ansible_facts.platform_version')
在上面的例子中,我们使用了setup模块,并将其输出的变量存储在setup_output
变量中。在之后的任务中,我们使用debug
模块来打印特定的输出。
请注意,在这里我们使用了json_query
函数,因为这个特定的输出是一个复杂的JSON对象。
确保在playbook中正确安装和配置了jmespath
库,以便使用json_query
函数。
通过使用变量来存储输出并在之后的任务中使用过滤器,您应该能够解决这个问题。