# Using when conditional to match string in output register

**URL:** <https://forum.ansible.com/t/using-when-conditional-to-match-string-in-output-register/25273>\
**Category:** Ansible Project\
**Created:** [August 16, 2017, 10:13pm UTC](https://forum.ansible.com/t/using-when-conditional-to-match-string-in-output-register/25273 "2017-08-16T22:13:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ted\_Meller](https://avatars.discourse-cdn.com/v4/letter/t/c89c15/32.png) [@Ted\_Meller](https://forum.ansible.com/u/Ted_Meller)\
**Post date:** [August 16, 2017, 10:13pm UTC](https://forum.ansible.com/t/using-when-conditional-to-match-string-in-output-register/25273/1 "2017-08-16T22:13:40Z")

</div>

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”)  
`

---

<div class="post-metadata">

**Author:** ![Mike\_Klebolt](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Klebolt](https://forum.ansible.com/u/Mike_Klebolt)\
**Post date:** [August 17, 2017, 8:10pm UTC](https://forum.ansible.com/t/using-when-conditional-to-match-string-in-output-register/25273/2 "2017-08-17T20:10:31Z")

</div>

Try:

`when: "'distribute-list' in output.stdout_lines"`
