puppetdb stringify结构化的事实,如哈希

时间:2016-06-10 06:38:34

标签: hash puppet stringify facter

我对puppetdb和我的结构化事实(哈希)有疑问。

哈希将通过我的puppetdb进行字符串化。

Ubuntu 14.04
puppetserver     = 3.8.7
facter           = 2.4.4
puppetdb         = 2.3.8-1

在我的客户端和服务器上的puppet.conf中,我已经包含:

stringify_facts  = false

在我的site.pp中,我有以下条目:

  if is_hash($::os) {
    notify {'hash':}
    notify {$os['family']:}
    }

    if is_string($::os) {
    notify {'string':}
    notify {$os['family']:}
    }

如果在我的服务器上的puppet.conf中:

storeconfigs          = true
storeconfigs_backend  = puppetdb

并且puppetdb正在运行。

我在客户端puppetrun上收到以下消息:

os is not a hash or Array when accesssing it with family.

如果我将site.pp更改为:

  if is_string($::os) {
    notify {'os is a string':}
  }

然后我收到消息 - > 'os是一个字符串'

如果我将服务器上的puppet.conf更改为:

storeconfigs          = false
storeconfigs_backend  = puppetdb

然后一切都好。事实上将确定为哈希。

有人有想法吗? 请帮忙 :) 摊儿

1 个答案:

答案 0 :(得分:0)

if is_hash($::os) {
  notify {'hash':}
  notify {$os['family']:}
}

if is_string($::os) {
  notify {'string':}
  notify {$os['family']:} <-- this line is failing
}

当你禁用puppetdb时,os这个事实变成了一个哈希,第一个是条件触发器。在这种情况下,使用$os['family']正确执行哈希查找。

当启用puppetdb并且事实被“字符串化”时,则触发第二个条件。哈希查找$os['family']将失败,因为os在这种情况下是一个字符串而不是哈希。您需要使用字符串查找$::osfamily替换哈希查找。

一些辅助信息: https://github.com/puppetlabs/facter/blob/2.4.6/lib/facter/operatingsystem/base.rb#L11 https://github.com/puppetlabs/facter/blob/2.4.6/lib/facter/kernel.rb#L12

相关问题