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

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
主站蜘蛛池模板: 汾阳市| 盱眙县| 乌兰察布市| 广饶县| 松阳县| 册亨县| 鄄城县| 青海省| 东方市| 武安市| 江门市| 新营市| 广东省| 金秀| 清新县| 长白| 漯河市| 桃园县| 普定县| 泾阳县| 抚宁县| 汾阳市| 陈巴尔虎旗| 开封市| 平江县| 开江县| 北海市| 浮梁县| 安新县| 五家渠市| 都安| 华宁县| 江陵县| 长泰县| 荆门市| 庄河市| 图木舒克市| 中西区| 巴东县| 鞍山市| 墨脱县|