Puppet
無法檢索來自 hiera 的 puppet 6 模板變數
將 puppet 程式碼從 puppet 3 遷移到 puppet 6 時遇到問題。
這是錯誤消息:
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, Failed to parse template puppetserver/var/test.sh.erb: Filepath: /opt/puppetlabs/environments/production/modules/puppetserver/templates/var/test.sh.erb Line: 21 Detail: undefined method `join' for nil:NilClass Did you mean? JSON (file: /opt/puppetlabs/environments/production/modules/puppetserver/manifests/config.pp, line: 38, column: 16) on node test.domain
/opt/puppetlabs/environments/production/modules/puppetserver/templates/var/test.sh.erb:
... for environment in <%= @pup_environments_array.join(' ') %>; do this that ...
在我的 hieradata JSON 中:
//test.domain { "puppetserver::working::environments": { "production": { "ensure": "present", }, "staging": { "ensure": "present" } } }
在 /opt/puppetlabs/environments/production/modules/puppetserver/manifests/config.pp 中:
class puppetserver::config { file {'/var/test.sh.erb': ensure => file, owner => 'puppet', group => 'puppet', content => template('puppetserver/var/test.sh.erb'), } }
在 /opt/puppetlabs/environments/production/modules/puppetserver/manifests/init.pp 中:
class puppetserver ( ) inherits puppetserver:params { $pup_environments= hiera_hash('puppetserver::working::environments',{}) $pup_environments_array = keys($pup_environments) include puppetserver::config }
- 木偶伺服器:6.0.2
- 傀儡代理:6.0.4
該程式碼在 puppet 3 上執行良好,但在 puppet 6 上執行良好。誰能告訴我原因以及如何解決它?
謝謝
好的。我自己得到了答案。
編碼:
file {'/var/test.sh.erb': ensure => file, owner => 'puppet', group => 'puppet', content => template('puppetserver/var/test.sh.erb'), }
需要在 /opt/puppetlabs/environments/production/modules/puppetserver/manifests/init.pp 而不是 /opt/puppetlabs/environments/production/modules/puppetserver/manifests/config.pp
在 puppet 3 上,我沒有拆分為許多清單。