我尝试在Linux服务器上创建一个Ansible角色来创建MOTD(当天的消息)。Ansible:包含管道的多行变量
我想在此文件中添加ASCII艺术,ASCII艺术是在我的模板中使用的变量中定义的。
所以我的ASCII艺术变量需要是多行,并包含多个特殊字符。
我尝试:
motd_asciiart: |
_____ _ _ __ _
/___| | | | /_| |
\ `--.| |_ __ _ ___| | _______ _____ _ __| |_| | _____ __
`--. \ __/ _` |/ __| |//_ \ \// _ \ '__| _| |/ _ \ \ /\//
/\__//|| (_| | (__| < (_) \ V/__/ | | | | | (_) \ V V/
\____/ \__\__,_|\___|_|\_\___/ \_/ \___|_| |_| |_|\___/ \_/\_/
但我得到这个错误:
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/Users/ydavid/Devops/ansible2/roles/umanit.motd/defaults/main.yml': line 3, column 9, but may be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
_____ _ _ __ _ /___| | | | /_| | ^here
我尝试添加“第一和最后一行,我有一个不同的错误:
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/Users/ydavid/Devops/ansible2/roles/umanit.motd/defaults/main.yml': line 7, column 74, but may be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
/\__//|| (_| | (__| < (_) \ V/__/ | | | | | (_) \ V V/ \____/ \__\__,_|\___|_|\_\___/ \_/ \___|_| |_| |_|\___/ \_/\_/ " ^here
你能帮助我吗?
我们可以逃脱一整块吗?
我发现了这个角色(https://github.com/picotrading/ansible-motd),它们做了同样的事情,但ASCII艺术是一线的,如果我可以,我会避免这种情况。
感谢您的建议。 有了这个解决方案,我怎样才能为我的主机使用不同的文件? 我需要一个通用文件和特定主机的一些例外 – voidAndAny
当然。我不明白这与原来的问题有何关系。您可以使用host_vars,group_vars或根据主机名包含文件。 – techraf