【问题标题】:Error: Could not autoload puppet/provider/...: cannot load such file错误:无法自动加载 puppet/provider/...:无法加载此类文件
【发布时间】:2014-08-06 20:23:13
【问题描述】:

我有一个使用 puppet apply 在一个 Windows VM (Windows 2008 R2) 上运行的 puppet 配置。我将代码复制到第二个虚拟机(相同操作系统)上的同一目录,但 puppet 应用失败并出现此错误:

Error: Could not autoload puppet/provider/mirrored_directory/zip: cannot load such file -- zip
Error: Could not autoload puppet/type/mirrored_directory: Could not autoload puppet/provider/mirrored_directory/zip: cannot load such file -- zip
Error: Could not autoload puppet/type/mirrored_directory: Could not autoload puppet/provider/mirrored_directory/zip: cannot load such file -- zip on node usb-tg
2008r2t2.xxxx.com
Error: Could not autoload puppet/type/mirrored_directory: Could not autoload puppet/provider/mirrored_directory/zip: cannot load such file -- zip on node usb-tg
2008r2t2.xxxx.com

这是我的源代码树:

C:\PHX_DEPLOYER
└───puppet
    ├───manifests
    └───modules
        ├───dotnet
        │   ├───files
        │   ├───lib
        │   │   └───puppet
        │   │       └───parser
        │   │           └───functions
        │   └───manifests
        ├───mirrored_directory
        │   └───lib
        │       └───puppet
        │           ├───provider
        │           │   └───mirrored_directory
        │           │       └───zip
        │           └───type
        ├───tfview
        │   ├───files
        │   │   └───tf
        │   └───manifests
        └───tf_package
            └───manifests

我启动了一个以管理员身份运行的 puppet cmd 控制台。我手动设置 HOMEDRIVE=C: 来解决一个问题(我们的引导脚本将其设置为 H: 驱动器)。 我设置了 modulepath 和 hiera_config 以匹配我在另一台机器上的内容:

puppet config set modulepath c:/phx_deployer/puppet/modules
puppet config set hiera_config c:/phx_deployer/puppet/hiera.yaml

我还运行了“puppet config print”并捕获了两台机器的输出并在其上使用了 diff 程序。唯一不同的设置与安全证书、IP 地址和机器名称有关。

从消息中可以清楚地看出,“puppet apply site.pp”在错误的位置查找我的 mirrored_directory 定义的类型。它在标准 puppet 位置查找,而不是我的目录树。我缺少什么设置?

注意:

c:\>puppet --version
3.4.3 (Puppet Enterprise 3.2.3)
c:\>ruby --version
ruby 1.9.3p484 (2013-11-22) [i386-mingw32]

更新:

原因是:我的 mirrored_directory 类型的自定义类型提供程序代码需要 ruby​​zip。我声明了对 ruby​​zip 包的依赖,但它永远不会超过编译阶段。

在nodes.pp中:

package { 'rubyzip':
  ensure   => 'latest',
  provider => 'gem',
}

在 tf_package 的 init.pp 中:

...
  mirrored_directory { $package_dir:
    source       => "${staging_dir}/${specific_version_label}/${zip_filename}",
    ensure       => 'present',
    do_deletes   => $do_deletes,
    exclude      => $exclude,
    include      => $include,
    require      => [Package['rubyzip'],File[$package_dir]],
    prefix_depth => $prefix_depth
  }
...

我对包有依赖,但这还不够。一位架构师如何构建 puppet 解决方案,以便您可以让 puppet 安装不是您的应用程序而是 puppet 类型本身需要的 gem?

更新:这是 puppet apply 的输出:

c:\phx_deployer\puppet\manifests>puppet apply site.pp --debug
Info: Loading facts in C:/ProgramData/PuppetLabs/puppet/var/lib/facter/concat_basedir.rb
Info: Loading facts in C:/ProgramData/PuppetLabs/puppet/var/lib/facter/custom_auth_conf.rb
Info: Loading facts in C:/ProgramData/PuppetLabs/puppet/var/lib/facter/facter_dot_d.rb
Info: Loading facts in C:/ProgramData/PuppetLabs/puppet/var/lib/facter/ip6tables_version.rb
Info: Loading facts in C:/ProgramData/PuppetLabs/puppet/var/lib/facter/iptables_persistent_version.rb
Info: Loading facts in C:/ProgramData/PuppetLabs/puppet/var/lib/facter/iptables_version.rb
Info: Loading facts in C:/ProgramData/PuppetLabs/puppet/var/lib/facter/pe_build.rb
Info: Loading facts in C:/ProgramData/PuppetLabs/puppet/var/lib/facter/pe_postgres_default_version.rb
Info: Loading facts in C:/ProgramData/PuppetLabs/puppet/var/lib/facter/pe_puppetdb_server_status.rb
Info: Loading facts in C:/ProgramData/PuppetLabs/puppet/var/lib/facter/pe_version.rb
Info: Loading facts in C:/ProgramData/PuppetLabs/puppet/var/lib/facter/postgres_default_version.rb
Info: Loading facts in C:/ProgramData/PuppetLabs/puppet/var/lib/facter/puppet_vardir.rb
Info: Loading facts in C:/ProgramData/PuppetLabs/puppet/var/lib/facter/root_home.rb
Info: Loading facts in C:/ProgramData/PuppetLabs/puppet/var/lib/facter/staging_http_get.rb
Info: Loading facts in C:/ProgramData/PuppetLabs/puppet/var/lib/facter/windows.rb
Debug: importing 'c:/phx_deployer/puppet/manifests/nodes.pp' in environment production
Debug: importing 'c:/phx_deployer/puppet/modules/dotnet/manifests/init.pp' in environment production
Debug: importing 'c:/phx_deployer/puppet/modules/dotnet/manifests/v4_5_1.pp' in environment production
Debug: Automatically imported dotnet::v4_5_1 from dotnet/v4_5_1 into production
Debug: hiera(): Hiera YAML backend starting
Debug: hiera(): Looking up dotnet::v4_5_1::version in YAML backend
Debug: hiera(): Looking for data source deployer_USB-TG2008R2T1.ef.com
Debug: hiera(): Cannot find datafile c:/phx_deployer/puppet/deployer_USB-TG2008R2T1.ef.com.yaml, skipping
Debug: hiera(): Looking for data source deployer_windows
Debug: hiera(): Found dotnet::v4_5_1::version in deployer_windows
Debug: hiera(): Looking up dotnet::v4_5_1::installer in YAML backend
Debug: hiera(): Looking for data source deployer_USB-TG2008R2T1.ef.com
Debug: hiera(): Cannot find datafile c:/phx_deployer/puppet/deployer_USB-TG2008R2T1.ef.com.yaml, skipping
Debug: hiera(): Looking for data source deployer_windows
Debug: hiera(): Found dotnet::v4_5_1::installer in deployer_windows
Debug: hiera(): Looking up dotnet::v4_5_1::temp_dir in YAML backend
Debug: hiera(): Looking for data source deployer_USB-TG2008R2T1.ef.com
Debug: hiera(): Cannot find datafile c:/phx_deployer/puppet/deployer_USB-TG2008R2T1.ef.com.yaml, skipping
Debug: hiera(): Looking for data source deployer_windows
Debug: hiera(): Found dotnet::v4_5_1::temp_dir in deployer_windows
Debug: hiera(): Looking up phoenix::packages in YAML backend
Debug: hiera(): Looking for data source deployer_USB-TG2008R2T1.ef.com
Debug: hiera(): Cannot find datafile c:/phx_deployer/puppet/deployer_USB-TG2008R2T1.ef.com.yaml, skipping
Debug: hiera(): Looking for data source deployer_windows
Debug: hiera(): Found phoenix::packages in deployer_windows
Debug: hiera(): Looking up phoenix::repository_dir in YAML backend
Debug: hiera(): Looking for data source deployer_USB-TG2008R2T1.ef.com
Debug: hiera(): Cannot find datafile c:/phx_deployer/puppet/deployer_USB-TG2008R2T1.ef.com.yaml, skipping
Debug: hiera(): Looking for data source deployer_windows
Debug: hiera(): Found phoenix::repository_dir in deployer_windows
Debug: hiera(): Looking up phoenix::staging_dir in YAML backend
Debug: hiera(): Looking for data source deployer_USB-TG2008R2T1.ef.com
Debug: hiera(): Cannot find datafile c:/phx_deployer/puppet/deployer_USB-TG2008R2T1.ef.com.yaml, skipping
Debug: hiera(): Looking for data source deployer_windows
Debug: hiera(): Found phoenix::staging_dir in deployer_windows
Debug: hiera(): Looking up phoenix::deployment_dir in YAML backend
Debug: hiera(): Looking for data source deployer_USB-TG2008R2T1.ef.com
Debug: hiera(): Cannot find datafile c:/phx_deployer/puppet/deployer_USB-TG2008R2T1.ef.com.yaml, skipping
Debug: hiera(): Looking for data source deployer_windows
Debug: hiera(): Found phoenix::deployment_dir in deployer_windows
Debug: hiera(): Looking up phoenix::collection_name in YAML backend
Debug: hiera(): Looking for data source deployer_USB-TG2008R2T1.ef.com
Debug: hiera(): Cannot find datafile c:/phx_deployer/puppet/deployer_USB-TG2008R2T1.ef.com.yaml, skipping
Debug: hiera(): Looking for data source deployer_windows
Debug: hiera(): Found phoenix::collection_name in deployer_windows
Debug: hiera(): Looking up phoenix::version_type in YAML backend
Debug: hiera(): Looking for data source deployer_USB-TG2008R2T1.ef.com
Debug: hiera(): Cannot find datafile c:/phx_deployer/puppet/deployer_USB-TG2008R2T1.ef.com.yaml, skipping
Debug: hiera(): Looking for data source deployer_windows
Debug: hiera(): Found phoenix::version_type in deployer_windows
Debug: hiera(): Looking up phoenix::version_label in YAML backend
Debug: hiera(): Looking for data source deployer_USB-TG2008R2T1.ef.com
Debug: hiera(): Cannot find datafile c:/phx_deployer/puppet/deployer_USB-TG2008R2T1.ef.com.yaml, skipping
Debug: hiera(): Looking for data source deployer_windows
Debug: hiera(): Found phoenix::version_label in deployer_windows
Debug: importing 'c:/phx_deployer/puppet/modules/tf_package/manifests/init.pp' in environment production
Debug: Automatically imported tf_package from tf_package into production
Debug: Failed to load library 'selinux' for feature 'selinux'
Debug: hiera(): Looking up tf_server in YAML backend
Debug: hiera(): Looking for data source deployer_USB-TG2008R2T1.ef.com
Debug: hiera(): Cannot find datafile c:/phx_deployer/puppet/deployer_USB-TG2008R2T1.ef.com.yaml, skipping
Debug: hiera(): Looking for data source deployer_windows
Debug: hiera(): Found tf_server in deployer_windows
Debug: hiera(): Looking up tf_port in YAML backend
Debug: hiera(): Looking for data source deployer_USB-TG2008R2T1.ef.com
Debug: hiera(): Cannot find datafile c:/phx_deployer/puppet/deployer_USB-TG2008R2T1.ef.com.yaml, skipping
Debug: hiera(): Looking for data source deployer_windows
Debug: hiera(): Found tf_port in deployer_windows
Debug: importing 'c:/phx_deployer/puppet/modules/tfview/manifests/init.pp' in environment production
Debug: Automatically imported tfview from tfview into production
Error: Could not autoload puppet/provider/mirrored_directory/zip: cannot load such file -- zip
Error: Could not autoload puppet/type/mirrored_directory: Could not autoload puppet/provider/mirrored_directory/zip: cannot load such file -- zip
Error: Could not autoload puppet/type/mirrored_directory: Could not autoload puppet/provider/mirrored_directory/zip: cannot load such file -- zip on node usb-tg
2008r2t1.ef.com
Error: Could not autoload puppet/type/mirrored_directory: Could not autoload puppet/provider/mirrored_directory/zip: cannot load such file -- zip on node usb-tg
2008r2t1.ef.com

我的 ruby​​ 模块 zipinstall.rb 的第一行。 require 'zip' 需要 gem ruby​​zip:

require 'rubygems'
require 'zip'

此代码又包含在我的提供程序代码 zip.rb 中:

# Resource Type: mirrored_directory
# Provider:      zip
#
# Provides the interface between the Puppet custom resource type 'mirrored_directory'
# and the ruby class 'ZipInstall::Unzipper'.
# This permits missing or changed files to be extracted from a Zip archive on a Windows system,
# while unchanged files are left alone.

require 'puppet/provider/mirrored_directory/zip/zipinstall'

Puppet::Type.type(:mirrored_directory).provide :zip do
  desc "Uses rubyzip to extract new or modified files from a zip archive on a Windows system."
  confine :osfamily => :windows
  defaultfor :osfamily => :windows

  include Puppet::Util::Warnings

  # The mirrored_directory resource exists iff the target directory exists.
  def exists?
    Puppet::FileSystem::File.exist?(@resource[:name])
  end

  # Assuming that the target directory is empty (or only contains excluded files),
  # extract all included files from the source archive and deposit them in the target directory
  # (or corresponding subdirectory).
  # Do not delete any files.
  def create
    Puppet::Util::Log.new(:level => :debug, :message => "create: About to unzip #{@resource[:source]}") 
    change_count = unzipper.extract(false)
    @property_hash[:ensure] = exists? ? :present : :absent
  end

  # Delete the contents of the target directory and subdirectories 
  # (other than those that are excluded).
  def destroy
    change_count = unzipper.delete
    @property_hash.clear
  end

  # Check if the files in the target directory match those in the source zip archive or not.
  def is_current
    Puppet::Util::Log.new(:level => :debug, :message => "is_current: About to examine #{@resource[:source]}") 
    !unzipper.has_differences?(false)
  end

  # Extract each file from the source archive that differs from the corresponding file
  # in the target directory. 
  # Optionally delete files found in the target directory but not in the source archive,
  # according to the parameter :do_deletes.
  def is_current=(value)
    unzipper_to_use = unzipper
    changes = unzipper_to_use.differences(false, false)
    count = unzipper_to_use.apply_changes(changes, @resource[:do_deletes])
    @property_hash[:is_current] = value
    0
  end

  # TODO: Search computer for all installed directories so that the installed 
  # mirrored_directory resource instances can be queried by puppet.
  def self.instances
    []
  end

  # Construct a new Unzipper, using these parameters supplied to the resource type:
  #   :source, :name, :exclude, :include
  # Supplies a logger that delegate to puppet's own logging.
  def unzipper
    # Puppet has numerous loggin levels, including:
    #    :crit, :err, :warning, :notice, :info, :debug
    logger = ->(level,message) {
      Puppet::Util::Log.new(:level => level, :message => message) 
    }
    ZipInstall::Unzipper.new(@resource[:source], @resource[:name], :prefix_depth => @resource[:prefix_depth], :exclude_files => @resource[:exclude], :include_files => @resource[:include], :logger => logger) 
  end

end

【问题讨论】:

    标签: windows puppet


    【解决方案1】:

    输出

    错误:无法自动加载 puppet/provider/mirrored_directory/zip:无法加载此类文件 -- zip

    似乎表明系统上缺少 zip 实用程序,或者 Puppet 找不到。

    【讨论】:

    • 关闭。 rubyzip gem 是必需的。即使我依赖它,puppet 也永远不会超过编译阶段。
    • 这很奇怪。仅仅因为一个提供者无法加载,目录仍然应该被编译。您可以将完整的输出粘贴到某处(包括详细/调试)吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    • 2015-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多