官术网_书友最值得收藏!

Using the confine method

The confine method can be used with a fact, as shown in the following code:

Puppet::Type.type(:mynewtype).provide(:myprovider) do
...
confine :osfamily => :redhat
...
end

The confine method could also use exisits to base its conditions on whether a certain file is present on the system under management. The following example demonstrates how the provider is restricted to only those systems where Puppet's .config file exists:

Puppet::Type.type(:mynewtype).provide(:myprovider) do
...
confine :exisits => Puppet[:config]
...
end

Another possibility is to base the conditions of the confine method on certain Puppet features (they are all listed in the source code directory at https://github.com/puppetlabs/puppet/tree/master/lib/puppet/feature), as shown in the following code:

Puppet::Type.type(:mynewtype).provide(:myprovider) do
...
confine :feature => :selinux
...
end

Finally, confine can accept a Boolean expression to restrict your provider, as shown in the following code:

Puppet::Type.type(:mynewtype).provide(:myprovider) do
...
confine :exisits => Puppet[:config]
...
confine :true => begin
if File.exists?(Puppet[:config])
File.readlines(Puppet[:config]).find {|line| line =~ /^\s*\[agent\]/ }
end
end
...
end
主站蜘蛛池模板: 乳源| 平安县| 桐城市| 获嘉县| 吴桥县| 河间市| 中方县| 翁牛特旗| 固始县| 报价| 古丈县| 三江| 涞水县| 丹巴县| 保定市| 浮山县| 武清区| 天长市| 山阴县| 红桥区| 佛学| 马公市| 台南市| 尼木县| 都江堰市| 龙川县| 团风县| 德清县| 万安县| 津南区| 武冈市| 建德市| 筠连县| 乐安县| 剑河县| 阿克| 水富县| 和林格尔县| 荔波县| 积石山| 灌云县|