如何过滤 Ansible 的 JSON 输出并与字符串进行比较?

How to filter Ansible's JSON output and compare with string?

我在 ansible 中使用 yum 模块来列出系统上的所有更新。输出是这样的:

results: [
  {
    "name": "rubygem-ffi", 
    "nevra": "0:rubygem-ffi-1.9.10-2.el7.x86_64", 
    "repo": "epel", 
    "epoch": "0", 
    "version": "1.9.10", 
    "release": "2.el7", 
    "yumstate": "available", 
    "arch": "x86_64"
  }
  {
    "name": "some-package", 
    "nevra": "blah", 
    "repo": "epel", 
    "epoch": "0", 
    "version": "6", 
    "release": "6.el7", 
    "yumstate": "available", 
    "arch": "x86_64"
  }
]

我在任务中使用的代码是:

  - name: yum list
    yum: list=updates
    register: output

我想要的是仅当在 JSON 输出中找到包名称时才打印调试消息。像这样:

  - debug: msg="Found it!"
    when: [output.I don't know the right filter] == "rubygem-ffi"

我尝试了 output.results.nameoutput.results|map(attribute='name')|list 之类的方法,但它们似乎不起作用

有什么线索吗?

可能还有其他解决方案。这个对我有用:

  - debug: msg='Found It!'
    when: item.name == 'rubygem-ffi'
    with_items: output.results