- Mastering Puppet 5
- Ryan Russell Yates Jason Southgate
- 163字
- 2021-07-16 17:46:17
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
推薦閱讀
- 數(shù)據(jù)通信:路由與交換技術(shù)
- 室內(nèi)分布系統(tǒng)規(guī)劃與設(shè)計:GSM/TD-SCDMA/TD-LTE/WLAN
- 電子線路CAD設(shè)計與仿真
- 通信原理
- 等離子彩電維修代換技法揭秘
- 想到做到:Android開發(fā)關(guān)鍵技術(shù)與精彩案例
- 艦船尾跡的電磁成像機(jī)理及特征提取技術(shù)
- 電子信息裝備體系論證理論、方法與應(yīng)用
- 現(xiàn)代交換技術(shù)
- 深入理解邊緣計算:云、邊、端工作原理與源碼分析
- 芯片設(shè)計——CMOS模擬集成電路版圖設(shè)計與驗證:基于Cadence IC 6.1.7(第2版)
- H3CNE實驗手冊
- 突破平面:會聲會影2018視頻編輯與制作
- 雷達(dá)目標(biāo)識別導(dǎo)論
- 移動互聯(lián)網(wǎng)異構(gòu)接入與融合控制