I'm trying to filter a list out of reach of Jinja2 when the elements contain a string, but the Jinja documentation does not seem clear enough to me to understand it.
This is what I have so far:
- name: run script command: /usr/tmp/run_script.py register: script_results - name: display run info debug: var: "{{script_results.stdout_lines | select(\"'running script' in script_results.stdout_lines\") }}"
But all I get is the error:
"<generator object _select_or_reject at 0x13851e0>": "VARIABLE IS NOT DEFINED!"
So, for example, if stdout_lines contains ["apples","running script one","oranges","running script two"] , I want to print
running script one running script two
They have documentation for selection and documentation for built-in tests , but they donβt display the βinβ test, and I donβt know how they work in the context of this mutable variable.
I tried to solve it like this:
- name: display run info debug: var: item with_items: "{{script_results.stdout_lines}}" when: "'running script' in item"
But this displays βgapsβ for every line that fails the test ... seemingly defeating the target!
source share