NameError:未初始化的常量Chef :: Resource :: PythonPip

时间:2017-06-20 02:54:55

标签: python ruby pip chef

enter image description here我正在挖掘社交媒体第2版的书,在Twitter上做一些数据科学。我下载了包含必要文件和文件夹等的文件... 在尝试流浪时(它使用Vagrant控制VM(virtualBox vm),其中将执行一些ipython笔记本),我发现了一个奇怪的错误:NoNameError:未初始化的常量Chef :: Resource :: PythonPip 这是default.tb文件: 默认[' python'] [' install_method'] ='包'

if node['python']['install_method'] == 'package'
  case node['platform']
  when "smartos"
   default['python']['prefix_dir']         = '/opt/local'
  else
    default['python']['prefix_dir']         = '/usr'
  end
else
  default['python']['prefix_dir']         = '/usr/local'
end

default['python']['binary'] = "#{node['python']
['prefix_dir']}/bin/python"

default['python']['url'] = 'http://www.python.org/ftp/python'
default['python']['version'] = '2.7.7'
default['python']['checksum'] = 
'3b477554864e616a041ee4d7cef9849751770bc7c39adaf78a94ea145c488059'
default['python']['configure_options'] = %W{--prefix=#{node['python']
['prefix_dir']}}

default['python']['setuptools_script_url'] = 
'https://bitbucket.org/pypa/setuptools/raw/0.8/ez_setup.py'
default['python']['pip_script_url'] = 'https://bootstrap.pypa.io/get-
pip.py'

这里是/deploy/python/providers/pip.rb(它识别出错误)

require 'chef/mixin/shell_out'
require 'chef/mixin/language'
include Chef::Mixin::ShellOut

def whyrun_supported?
  true
end

# the logic in all action methods mirror that of
# the Chef::Provider::Package which will make
# refactoring into core chef easy

action :install do
  # If we specified a version, and it's not the current version, move 
to the specified version
  if new_resource.version != nil && new_resource.version != 
current_resource.version
    install_version = new_resource.version
  # If it's not installed at all, install it
  elsif current_resource.version == nil
    install_version = candidate_version
  end

  if install_version
    description = "install package #{new_resource} version #
{install_version}"
    converge_by(description) do
      Chef::Log.info("Installing #{new_resource} version #
{install_version}")
      status = install_package(install_version)
      if status
        new_resource.updated_by_last_action(true)
      end
    end
  end
end

action :upgrade do
  if current_resource.version != candidate_version
    orig_version = current_resource.version || "uninstalled"
    description = "upgrade #{current_resource} version from #
{current_resource.version} to #{candidate_version}"
    converge_by(description) do
      Chef::Log.info("Upgrading #{new_resource} version from #
{orig_version} to #{candidate_version}")
      status = upgrade_package(candidate_version)
      if status
        new_resource.updated_by_last_action(true)
      end
    end
  end
end

action :remove do
  if removing_package?
   description = "remove package #{new_resource}"
   converge_by(description) do
     Chef::Log.info("Removing #{new_resource}")
      remove_package(new_resource.version)
     new_resource.updated_by_last_action(true)
    end

2 个答案:

答案 0 :(得分:1)

更改为poise-python是最好的解决方案,但可以修补旧的python cookbook。了解发生此错误的原因可能有助于其他人在自定义食谱中遇到类似问题,因为他们转移到了Chef 13。

Chef 13不再为自定义资源创建模块常量,如发行说明https://discourse.chef.io/t/chef-client-13-released/10735

中所述

折旧的python cookbook中只需更改两行代码,因此可与Chef 13一起使用。

在providers / virtualenv.rb中:

-  @current_resource = Chef::Resource::PythonVirtualenv.new(new_resource.name)
+  @current_resource = Chef::Resource.resource_for_node(:python_virtualenv, node).new(new_resource.name)

在providers / pip.rb中:

-  @current_resource = Chef::Resource::PythonPip.new(new_resource.name)
+  @current_resource = ::Chef::Resource.resource_for_node(:python_pip, node).new(new_resource.name)

答案 1 :(得分:0)

python食谱明确标记为已弃用,并且根本不支持Chef 13(或者只是一般情况下,但我不会为Chef 13修复它)。请改用poise-python