Puppet

Puppet:如何寫出合適的“條件和條件”語句?

  • February 16, 2015

我寫了一個影響我公司所有代理伺服器的“每日消息”Puppet 模組。在模板文件中,我有以下“if 語句”:

<% if @hostname !~ /^haproxy\d+/ and @hostname =~ /proxy\d+/ -%>
if [ "$(cat $LBMEMFILE)" = "0" ]; then
echo -e "\e[35m Membeship in LB:  Yes"
elif [ "$(cat $LBMEMFILE)" = "2" ]; then
echo -e "\e[35m Membeship in LB:    No $LISTMEMFILE"
fi
<% end -%>

它的意義:

如果主機名是 proxy0-100 而不是 ^haproxy0-100,則在 motd 腳本中添加一行。

但由於某種原因,這種說法不起作用。

我也嘗試使用“除非”,但無濟於事。

如果我刪除第一行中“and”之後的語句,它就像一個魅力。

這是我得到的錯誤:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: undefined method `empty?' for nil:NilClass at /etc/puppet/environments/production/manifests/site.pp:1 on node haproxy02.company.com
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

我究竟做錯了什麼?

提前致謝

我發現了問題……文件中有一個額外的空間.yaml導致了錯誤。謝謝你的幫助。

引用自:https://serverfault.com/questions/667991