0

I am using the yum module in ansible to list all updates on a system. The output is something like this:

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"
  }
]

And the code I use in tasks is:

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

What I want is to print a debug message only when the name of a package is found in the JSON output. Like this:

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

I tried something like output.results.name or output.results|map(attribute='name')|list but they don't seem to work

Any clues?

1 Answer 1

1

There may be other solutions. This one works for me:

  - debug: msg='Found It!'
    when: item.name == 'rubygem-ffi'
    with_items: output.results
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.