2

I need to reject "*" from stdout lines.

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

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

Playbook output:

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": ""}
3

Regex '[*]' works. The play below

  vars:
    my_lines:
      - "rchinnn01"
      - "rchinnn02"
      - "*"
  tasks:
    - debug:
        msg: "{{ my_lines|reject('match', '[*]')|list }}"

gives (abridged):

ok: [localhost] => {
    "msg": [
        "rchinnn01", 
        "rchinnn02"
    ]
}
| improve this answer | |
0

Please use as below:

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

Please check jinja2 version details

| improve this answer | |
  • I used provided syntax, but it's taking only "" from stdout_lines. But my requirement is vice-versa, I need everything to be assigned to a variable except "" . I tried by replacing rchinnn* with "*", but it's taking * as wildcard and it's rejecting everything. – Pandu Feb 12 '19 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.