select/reject filter parameters

In for example, the following:

{{ hostvars[host][‘java_one’][‘stderr_lines’] | reject(‘contains’, ‘OpenJDK’) }}

or
{{ hostvars[host][‘java_one’][‘stderr_lines’] | select(‘contains’, ‘Java™’) }}

how can i add a second value to select or reject? I want the action to take place if “OpenJDK” OR “Java™’” is found.

Instead of "Testing if a list contains a value"
https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html#testing-if-a-list-contains-a-value
you might want to use "Testing strings"
https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html#testing-strings

For example, use *search* and test the list is not empty to take
action if "OpenJDK" OR "Java(TM)" is found

  when: list_of_lines|
        select('search', 'OpenJDK|Java\(TM\)')|
        list>
        length > 0

Ok. Here’s the entire playbook:

What content of prodjava.txt do you expect?

This:

myserver1.mydomain.com
[‘java version “1.7.0_71”’, ‘Java™ SE Runtime Environment (build 1.7.0_71-b14)’, ‘Java HotSpot™ 64-Bit Server VM (build 24.71-b01, mixed mode)’]

myserver2.mydomain.com

[‘java version “1.7.0_71”’, ‘Java™ SE Runtime Environment (build 1.7.0_71-b14)’, ‘Java HotSpot™ 64-Bit Server VM (build 24.71-b01, mixed mode)’]

Try this

        content: |
          {% for host in ansible_play_hosts %}
          {% set present = hostvars[host].java_one.stderr_lines|
                           select('search', 'OpenJDK|Java\(TM\)')|
                           list>length > 0 %}
          {{ host }}
          {% if present %}{{ hostvars[host].java_one.stderr_lines
        }}{% endif %}

          {% endfor %}

For details see https://jinja.palletsprojects.com/en/master/

OK, almost got this! And, I probably didn’t explain what I’m after very well. Based on the code you just provided, this is the output, e.g.:

somehost.mydomain.com
[‘java version “1.7.0_65”’, ‘OpenJDK Runtime Environment (rhel-2.5.1.2.el6_5-x86_64 u65-b17)’, ‘OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)’]

anotherhost.mydomain.com
[‘java version “1.7.0_71”’, ‘Java™ SE Runtime Environment (build 1.7.0_71-b14)’, ‘Java HotSpot™ 64-Bit Server VM (build 24.71-b01, mixed mode)’]

However, I only want records containing “Java™” returned. How do I adjust the code to do that?

Sorry, I’m being messy here. If i try this, “select(‘search’, ‘!OpenJDK|Java(TM)’)|”, I get output like this:

somehost.mydomain.com
anotherhost.mydomain.com
[‘java version “1.7.0_71”’, ‘Java™ SE Runtime Environment (build 1.7.0_71-b14)’, ‘Java HotSpot™ 64-Bit Server VM (build 24.71-b01, mixed mode)’]