[英]Puppet: unable to get hiera variable
我已經使用hiera幾個星期了,幾天前我開始得到那種消息時一切正常!
錯誤:無法從遠程服務器檢索目錄:SERVER上的錯誤400:無法在任何Hiera數據文件中找到數據項nom並且節點上沒有提供默認值d0puppetclient.victor-buck.com
警告:未在失敗的目錄上使用緩存
錯誤:無法檢索目錄; 跳過運行
所以我試着做一個非常簡單的測試,以檢查問題是否來自我上次的代碼更改,我仍然收到此消息。 我不能再獲得hiera變量了。 在我做的測試下面:
hiera.yaml:
---
:backends:
- yaml
:yaml:
:datadir: /etc/puppet/hieradata
:hierarchy:
- common
site.pp:
# /etc/puppet/manifests/site.pp
case $operatingsystem {
'Solaris': { include role::solaris }
'RedHat', 'CentOS': { include redhat::roles::common }
/^(Debian|Ubuntu)$/: { include role::debian }
# default: { include role::generic }
}
case $hostname {
/^d0puppetclient/: { include test }
}
test.pp:
class test{
$nom = hiera('nom')
file {"/root/test.txt":
ensure => file,
source => "/etc/puppet/test.txt.erb",
}
}
test.txt.erb:
<%= nom %>
有什么想解決這個問題嗎? 我認為這可能是一個文件訪問權限問題,所以我試圖訪問某些文件( 755
)並且它不起作用...
您需要在common.yaml中定義nom
才能保存值。 如果您不打算設置默認值,則可以設置默認值並有條件地創建該文件。
class test {
$nom = hiera('nom', false)
if $nom {
file { '/root/test.txt':
ensure => file,
content => template('test/test.txt.erb')
}
}
}
請注意我如何使用content
而不是source
。 使用erb
模板時,您需要使用template()
函數指定content
。
如果您使用source
,則需要一個文件而不是erb
模板。
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.