# hardware_platform.rb
Facter.add('hardware_platform') do
setcode do
Facter::Core::Execution.exec('/bin/uname --hardware-platform')
end
end
我想執行它,當我給facter --puppet
。這些信息並不包含在日誌中。請告訴我如何從事實的信息我想執行我在自己製作的自定義事實
# hardware_platform.rb
Facter.add('hardware_platform') do
setcode do
Facter::Core::Execution.exec('/bin/uname --hardware-platform')
end
end
我想執行它,當我給facter --puppet
。這些信息並不包含在日誌中。請告訴我如何從事實的信息我想執行我在自己製作的自定義事實
Facter提供裝載事實的多種方法:
- $ LOAD_PATH,或Ruby庫加載路徑
- 的--custom-dir命令行選項
- 環境變量「FACTERLIB」
您可以使用這些方法distributin之前做的事情一樣測試文件在本地克他們,或者你可以安排在某些機器上有一組特定的事實。
使用Ruby加載路徑
Facter搜索名爲facter子目錄在Ruby $LOAD_PATH
變量的所有目錄,並加載這些目錄中的所有Ruby文件。如果您在$LOAD_PATH
有一個目錄像~/lib/ruby
,設立這樣的:
#~/lib/ruby
└── facter
├── rackspace.rb
├── system_load.rb
└── users.rb
Facter負荷facter/system\_load.rb
,facter/users.rb
,並facter/rackspace.rb
。
使用--custom-dir
命令行選項
Facter可以指定一個目錄中搜索自定義事實的命令行上的多個--custom-dir
選項。 Facter嘗試加載指定目錄中的所有Ruby文件。這允許你做這樣的事情:
$ ls my_facts
system_load.rb
$ ls my_other_facts
users.rb
$ facter --custom-dir=./my_facts --custom-dir=./my_other_facts system_load users
system_load => 0.25
users => thomas,pat
使用FACTERLIB
環境變量
Facter還檢查環境變量FACTERLIB
的分隔(分號用於Windows和冒號對於所有其他平臺)集目錄,並嘗試加載這些目錄中的所有Ruby文件。這允許你做這樣的事情:
$ ls my_facts
system_load.rb
$ ls my_other_facts
users.rb
$ export FACTERLIB="./my_facts:./my_other_facts"
$ facter system_load users
system_load => 0.25
users => thomas,pat
來源:https://docs.puppet.com/facter/3.6/custom_facts.html#loading-custom-facts
您需要投入一些精力來提供你已經嘗試過精確的細節,文檔您已經閱讀等等。 –
這是傀儡模塊的一部分嗎? – ptierno