Using when conditional to match string in output register

36 views
Skip to first unread message

Ted Meller

unread,
Aug 16, 2017, 6:13:41 PM8/16/17
to Ansible Project
Im unable to search my output variable for a specified string that im using for a when statement. The code below is supposed to check for the string "distribute-list" in the output variable but when run the playbook it gives the error.

fatal: : FAILED! => {"failed": true, "msg": "The conditional check 'output | search(\"distribute-list\")' failed. The error was: Unexpected templating type error occurred on ({% if output | search(\"distribute-list\") %} True {% else %} False {% endif %}): expected string or buffer\n\nThe error appears to have been in '/home/khibiny/test4.yml': line 26, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n  - debug:\n    ^ here\n"}
        to
retry, use: --limit @/home/khibiny/test4.retry

Here is the code that is causing issue:


   register: output

 
- debug:
      msg
: "{{output.stdout_lines}}"
   
when: output | search("distribute-list")


Mike Klebolt

unread,
Aug 17, 2017, 4:10:31 PM8/17/17
to Ansible Project
Try:
when: "'distribute-list' in output.stdout_lines"
Reply all
Reply to author
Forward
0 new messages