我无法在输出变量中搜索我用于 when 语句的指定字符串。下面的代码应该检查输出变量中的字符串“distribute-list”,但是当运行剧本时它会给出错误。
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"}
这是导致问题的代码:
- ios_command:
commands: show run | sec ospf
provider: "{{cli}}"
register: output
- debug:
msg: "{{output.stdout_lines}}"
when: output | search("distribute-list")
希望得到一些帮助。提前致谢。
search
期望字符串作为输入,但是output
是一个具有不同属性的字典。
你应该很好地与
when: output.stdout | join('') | search('distribute-list')
你需要中间join
在这里,因为对于ios
-家庭模块stdout
是一个字符串列表,并且stdout_lines
是一个列表的列表(而对于通常的情况command
module stdout
是一个字符串并且stdout_lines
是一个字符串列表)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)