從目錄快速安裝多個 puppet 模組

從目錄快速安裝多個 puppet 模組

有沒有一種方法可以透過一個指令從一個目錄安裝多個木偶模組?
我有一個目錄,其中包含從 forge 下載的 tar.gz 形式的多個 puppet 模組,我需要安裝所有模組。然而,puppet module install只需要一個模組的參數。我最初使用 bash 循環puppet module install為目錄中的每個模組呼叫一次。然而,我很快就發現,由於 puppet 啟動時間很慢(這似乎是由於 ruby​​ 加載所有 gem 的速度很慢),我的系統上安裝每個模組需要 1.6 到 2 秒。由於我添加了更多要安裝的模組,安裝它們的時間就成了一個問題。

不含參數執行 puppet 或只puppet help需要 1.6 到 2 秒;puppet module install當模組已經安裝時,運行也需要很長時間。這表示安裝模組的大部分時間只是puppet的啟動時間,而不是安裝模組所需的時間。當我 strace puppet 調用時,有數千個 stat 和 lstat 調用,導致 ENOENT 沒有這樣的文件或目錄,根據我的研究,我相信 ruby​​ 正在加載 gem,其中一些使用共享庫。

我要安裝模組的主機位於隔離網路上,無法存取 forge,因此直接從 forge 安裝不是一個選擇。

我簡要地研究了使用 Bolt,但在文件中找不到從本機目錄安裝模組的方法。

答案1

我圍繞 puppet 模組安裝編寫了一個簡單的 ruby​​ 包裝器腳本作為目前的解決方法。這不是一個理想的解決方案,因為腳本捕獲SystemExit並調用“內部”測試方法,並且因為我必須維護這個額外的腳本。我希望呼叫一個木偶提供的命令來提供安裝多個模組的行為,但這個包裝器腳本現在應該可以幫助我了。

#!/opt/puppetlabs/puppet/bin/ruby

begin
  require 'puppet/util/command_line'
  ARGV.each { |arg|
    begin
      Puppet::Util::Commandline.new('puppet', ['module', 'install', arg]).execute
    rescue SystemExit => e
      if e.success?
        $stderr.puts e.message
      else
        raise
      end
    end
    Puppet.settings.send(:clear_everything_for_tests) # needed after each puppet Commandline call to clear the global variables in order to call Commandline execute again
  }
rescue LoadError => e
  $stderr.puts e.message
  exit(1)
end

相關內容