gpt4 book ai didi

linux - 覆盖因子 'osfamily' 值

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:50:13 25 4
gpt4 key购买 nike

我通过从我的模块中调用扩展了一个模块 (pdxcat/collectd)。基本模块倾向于将 Amazon Linux 操作系统系列标识为“Redhat”,但 puppet 在 Amazon Linux 操作系统上安装的事实将操作系统报告为“Linux”。

我想通过在调用基本模块之前将 osfamily 的 facter 值从 Linux 覆盖到 Redhat 来纠正这个错误。

mymodule/lib/facter 中的 osfamily.rb 是

Facter.add('osfamily') do
setcode do
case Facter.value(:operatingsystem)
when "Amazon"
"RedHat"
else
Facter.value("kernel")
end
end
end

但问题是,我无法覆盖 osfamily 值。即使从 osfamily.rb 加载事实后,osfamily 仍被报告为“Linux”而不是“Redhat”。

我的代码可以正确处理新值,例如 osfamilytestoperatingsystemreleasetest但不适用于 osfamily 等现有值或 operatingsystemrelease .

Puppet Version: 2.7.25 
Facter Version: 1.6.18
Operating System:
Amazon Linux 2015.03
Puppet installation steps:
yum install puppet

最佳答案

我认为尝试覆盖社区模块的内置因子值是一种反模式。也就是说,在某些情况下(如上述)您应该能够覆盖事实,因为这不是社区模块(例如内部模块)。

如果这是一个内部模块,你应该看看事实优先级 - https://docs.puppetlabs.com/facter/3.0/custom_facts.html#fact-precedence

The way that Facter decides the issue of resolution precedence is the weight property. Once Facter rules out any resolutions that are excluded because of confine statements, the resolution with the highest weight is evaluated first. If that resolution returns nil, Facter moves on to the next resolution (by descending weight) until it gets a value for the fact.

By default, the weight of a fact is the number of confines for that resolution, so that more specific resolutions takes priority over less specific resolutions.

给它赋予 100 的权重,看看事实分辨率给你什么。

Facter.add('osfamily') do
has_weight 100
setcode do
case Facter.value(:operatingsystem)
when "Amazon"
"RedHat"
else
Facter.value("kernel")
end
end
end

关于linux - 覆盖因子 'osfamily' 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32338921/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com