6

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: [192.168.3.252]: 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"}

Here is the code that is causing issue:

 - ios_command:
 commands: show run | sec ospf
 provider: "{{cli}}"
 register: output
 - debug:
 msg: "{{output.stdout_lines}}"
 when: output | search("distribute-list") 

Would appreciate some help. Thanks in advance.

asked Aug 17, 2017 at 14:02

1 Answer 1

10

search expects string as input, but output is a dict with different properties.

You should be good with

when: output.stdout | join('') | search('distribute-list')

you need intermediate join here, because for ios-family modules stdout is a list of strings, and stdout_lines is a list of lists (whereas for usual command module stdout is a string and stdout_lines is a list of strings).

answered Aug 17, 2017 at 14:13
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. Posted this in another forum and couldnt get help. Posted in Stack Overflow and less than an hour later I get help. thanks a lot

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.