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

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
主站蜘蛛池模板: 汾西县| 五莲县| 泰和县| 攀枝花市| 黄梅县| 延津县| 东海县| 海淀区| 余庆县| 思南县| 麦盖提县| 米脂县| 会理县| 巴彦淖尔市| 齐齐哈尔市| 阜城县| 田阳县| 鞍山市| 临澧县| 堆龙德庆县| 衡阳市| 临洮县| 固镇县| 新兴县| 麻江县| 乌拉特后旗| 申扎县| 深泽县| 盘山县| 巍山| 馆陶县| 宽甸| 阜城县| 历史| 枣强县| 阜康市| 台北县| 青神县| 泾阳县| 西和县| 明星|