Use Ansible jinja2 filter reject in stdout_lines

16 views
Skip to first unread message

Pandu jh

unread,
Feb 12, 2019, 12:20:49 PM2/12/19
to Ansible Project
I need to reject "*" from stdout lines. all values from stdout_lines except "*" symbol to be saved to "nfs_clients" variable

    "stdout_lines": [
        "rchinnn01",
        "rchinnn02",
        "*"
    ]

   - set_fact:
     nfs_clients:  "{{ nfs_clients_out.stdout_lines | reject('search','*') | list }}"

TASK [set_fact] ***************************************************************************************************** An exception occurred during task execution. To see the full traceback, use -vvv. The error was: error: nothing to repeat fatal: [rchinnn03]: FAILED! => {"msg": "Unexpected failure during module execution.", "stdout": ""}

Kai Stian Olstad

unread,
Feb 12, 2019, 12:35:20 PM2/12/19
to ansible...@googlegroups.com
On 12.02.2019 18:20, Pandu jh wrote:
> I need to reject "*" from stdout lines. all values from stdout_lines
> except
> "*" symbol to be saved to "nfs_clients" variable
>
> "stdout_lines": [
> "rchinnn01",
> "rchinnn02",
> "*"
> ]
>
> - set_fact:
> nfs_clients: "{{ nfs_clients_out.stdout_lines |
> reject('search','*') | list }}"

search takes regexp and * is a regexp special character so you need to
escape it or just change search to equalto.
Your indentation is also off, nfs_clients need to extra spaces in front.

- set_fact:
nfs_clients: "{{ nfs_clients_out.stdout_lines |
reject('equalto','*') | list }}"


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages