1

ubuntu 11.10 VM 内のopscode Python cookbookを使用して、Chef を使用してノードに virtualenv をインストールしようとしています。特に、アプリケーションレシピを使用して、Django と Gunicorn に対してこれを行います。

python_virtual リソースのデフォルト設定は python2.6 です。次のように、ロール ファイルのデフォルト属性をオーバーライドして、python2.7 を指定しようとしています。

override_attributes(
  :authorization => {
    :sudo => {
      :users => ["vagrant"],
      :passwordless => true
    }
  },
  :python_virtualenv => {
    :interpreter => "python2.7"
  }
)

ただし、これは機能しません。

[Thu, 26 Jan 2012 17:34:31 -0500] FATAL: Chef::Exceptions::ShellCommandFailed: execute[virtualenv --python=python2.6 /home/deploy/shared/env] (/srv/chef/file_store/cookbooks/python/providers/virtualenv.rb line 28) had an error: Chef::Exceptions::ShellCommandFailed: Expected process to exit with [0], but received '3'
---- Begin output of virtualenv --python=python2.6 /home/deploy/shared/env ----
STDOUT: The executable python2.6 (from --python=python2.6) does not exist

ここでデフォルト値をオーバーライドするための適切な構文は何ですか?

4

3 に答える 3

1

リソースを実際に変更せずにリソースのデフォルト値を変更することはできないと確信しています。おそらくあなたが望んでいた答えではありません。リソースを使用する場合は、オーバーライド値を指定する必要があります。

于 2012-03-22T02:55:40.517 に答える
1

インタープリターを application::django プロバイダーからのパラメーターにするために私がしたことは次のとおりです。

diff --git a/cookbooks/application_python/providers/gunicorn.rb b/cookbooks/application_python/providers/gunicorn.rb
index 08c5925..210e508 100644
--- a/cookbooks/application_python/providers/gunicorn.rb
+++ b/cookbooks/application_python/providers/gunicorn.rb
@@ -27,6 +27,7 @@ action :before_compile do
   django_resource = new_resource.application.sub_resources.select{|res| res.type == :django}.first
   gunicorn_install "gunicorn-#{new_resource.application.name}" do
     virtualenv django_resource ? django_resource.virtualenv : nil
+    interpreter django_resource.interpreter
   end

   if !new_resource.restart_command
diff --git a/cookbooks/application_python/resources/django.rb b/cookbooks/application_python/resources/django.rb
index 6429cee..b4d4b38 100644
--- a/cookbooks/application_python/resources/django.rb
+++ b/cookbooks/application_python/resources/django.rb
@@ -30,7 +30,7 @@ attribute :settings_template, :kind_of => [String, NilClass], :default => nil
 attribute :local_settings_file, :kind_of => String, :default => 'local_settings.py'
 attribute :debug, :kind_of => [TrueClass, FalseClass], :default => false
 attribute :collectstatic, :kind_of => [TrueClass, FalseClass, String], :default => false

 def local_settings_base
   local_settings_file.split(/[\\\/]/).last
diff --git a/cookbooks/application_python/resources/gunicorn.rb b/cookbooks/application_python/resources/gunicorn.rb
index 50d3c2b..f68c868 100644
--- a/cookbooks/application_python/resources/gunicorn.rb
+++ b/cookbooks/application_python/resources/gunicorn.rb
@@ -42,3 +42,4 @@ attribute :logfile, :kind_of => String, :default => '-'
 attribute :loglevel, :kind_of => [String, Symbol], :default => :info
 attribute :proc_name, :kind_of => [String, NilClass], :default => nil
 attribute :command, :kind_of => [String, NilClass], :default => ""
+attribute :interpreter, :kind_of => String, :default => nil
diff --git a/cookbooks/gunicorn/providers/install.rb b/cookbooks/gunicorn/providers/install.rb
index 19266ad..67f526c 100644
--- a/cookbooks/gunicorn/providers/install.rb
+++ b/cookbooks/gunicorn/providers/install.rb
@@ -20,6 +20,7 @@

 action :install do
   python_virtualenv new_resource.virtualenv do
+    interpreter new_resource.interpreter
     action :create
   end if new_resource.virtualenv

diff --git a/cookbooks/gunicorn/resources/install.rb b/cookbooks/gunicorn/resources/install.rb
index 6c7f8b6..f52fe09 100644
--- a/cookbooks/gunicorn/resources/install.rb
+++ b/cookbooks/gunicorn/resources/install.rb
@@ -21,6 +21,7 @@
 actions :install

 attribute :virtualenv, :kind_of => String, :default => nil
+attribute :interpreter, :kind_of => String, :default => nil

 def initialize(*args)
   super
diff --git a/cookbooks/webplayer/recipes/default.rb b/cookbooks/webplayer/recipes/default.rb
index 8c812ce..1981c09 100644
--- a/cookbooks/webplayer/recipes/default.rb
+++ b/cookbooks/webplayer/recipes/default.rb
@@ -22,6 +22,11 @@ file "/etc/chef/deploy" do
   :create_if_missing
 end

+directory "/root/.ssh" do
+  owner "root"
+  group "root"
+end
+
 file "/root/.ssh/config" do
   owner "root"
   group "root"
于 2013-03-25T19:26:51.393 に答える
0

Python インタープリターにフル パスを渡す必要がある場合があります。

:interpreter => "/usr/bin/python2.7"
于 2012-01-26T23:25:50.227 に答える