Reputation: 2568
Can someone let me know how to remove null values from stdout_lines.
Output
"stdout_lines": [
"",
"D:\\Program Files\\Apache Softwarecoder.exe",
"",
"D:\\Program Files\\Apache Software\\cat8.5.exe",
"",
"",
""
]
Expected Output
"stdout_lines": [
"D:\\Program Files\\Apache Softwarecoder.exe",
"D:\\Program Files\\Apache Software\\cat8.5.exe"
]
I tried as below
path: "{{test.stdout_lines | rejectattr('') }}"
path: "{{test.stdout_lines | reject('')|list }}"
path: "{{test.stdout_lines | rejectattr('')|list }}"
But I Get error as below or no change in output:
"path": "<generator object _select_or_reject at 0x7fb349f45cd0>"
Upvotes: 2
Views: 753
Reputation: 67959
reject does the job
path: "{{ stdout_lines|reject('match', '^$')|list }}"
as well as select
path: "{{ stdout_lines|select('match', '.+')|list }}"
Upvotes: 2