模板字符串时出现模板错误:意外的字符 u - Ansible [英] Template error while templating string: unexpected char u - Ansible
问题描述
当执行 playbook 在远程主机上运行命令并使用 shell 传递输出时,出现以下错误.
When executing a playbook to run a command in a remote host and pass the output using shell, getting below error.
致命:[master1]:失败!=> {} MSG:模板化时模板错误字符串:4 处的意外字符 u'a'.字符串:{{54aa7fda16833bff8358b6bd1157df2d9caa26b2}}
fatal: [master1]: FAILED! => {} MSG: template error while templating string: unexpected char u'a' at 4. String: {{54aa7fda16833bff8358b6bd1157df2d9caa26b2}}
下面是我的剧本内容
- name: 'Play1'
hosts: master
tasks:
- name: 'Execute command'
shell: ''sh generate_ticket.sh" #command to generate ticket
register: shell_output
- name: 'debug shell_output'
debug:
var="{{ shell_output.stdout | from_yaml }}"
当我对 msg 尝试同样的操作并且不尝试过滤时,输出将被打印出来,没有任何错误.但是我更喜欢使用 var 因为它最适合我的进一步要求.如果票号是不同的字符串,我不会遇到任何问题.请参阅以下内容:
When I try the same with msg and don't try to filter then the output is printed without any error. However I prefer to use var as it suits best for my further requirements. If the ticket number is a different string I do not face any issues. Please see below:
输出:
ok: [master1] => {}
MSG:
54aa7fda16833bff8358b6bd1157df2d9caa26b2
Playbook :
- name: 'Play1'
hosts: master
tasks:
- name: 'Execute command'
shell: ''sh generate_ticket.sh" #command to generate ticket
register: shell_output
- name: 'debug shell_output'
debug: msg="{{ shell_output.stdout | from_yaml }}"
推荐答案
当我在 shell_output.stdout
var="{{ 'shell_output.stdout' | from_yaml}}"
如果有人有比这更好的解决方法,请告诉我.
Let me know if anybody has a better fix than this.
这篇关于模板字符串时出现模板错误:意外的字符 u - Ansible的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!