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

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
主站蜘蛛池模板: 武鸣县| 铜梁县| 济南市| 钟祥市| 巫山县| 石泉县| 巴彦淖尔市| 贵南县| 阿拉善左旗| 博客| 安庆市| 翁牛特旗| 南涧| 漳浦县| 定兴县| 百色市| 福州市| 正镶白旗| 西昌市| 砀山县| 滦平县| 吴忠市| 娱乐| 福贡县| 广州市| 科尔| 高尔夫| 双流县| 根河市| 舟山市| 民勤县| 武定县| 体育| 寿光市| 南丹县| 廉江市| 隆林| 隆德县| 金阳县| 深泽县| 湘潭市|