我嘗試在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