So verwenden Sie das Python-LWRP mit Opsworks/Chef 11
-
20-12-2019 - |
Frage
Ich bin neu bei Chef/OpsWorks und versuche ein einfaches Rezept, um Django 1.6 auf einer Ubuntu 12.04-Instanz zu installieren:
python_pip "Django" do
version "1.6"
action :install
end
Meine Provider/pip.rb und Provider/virtualenv.rb scheinen das zu überschreiben, was angeblich bereits geladen wurde:
DEBUG: Loading cookbook python's providers from /opt/aws/opsworks/releases/20131107153140_213/site-cookbooks/python/providers/pip.rb
DEBUG: Loaded contents of /opt/aws/opsworks/releases/20131107153140_213/site-cookbooks/python/providers/pip.rb into a provider named python_pip defined in Chef::Provider::PythonPip
DEBUG: Loading cookbook python's providers from /opt/aws/opsworks/releases/20131107153140_213/site-cookbooks/python/providers/virtualenv.rb
DEBUG: Loaded contents of /opt/aws/opsworks/releases/20131107153140_213/site-cookbooks/python/providers/virtualenv.rb into a provider named python_virtualenv defined in Chef::Provider::PythonVirtualenv
DEBUG: Loading cookbook python's providers from /opt/aws/opsworks/releases/20131107153140_213/site-cookbooks/python/providers/pip.rb
INFO: PythonPip light-weight provider already initialized -- overriding!
DEBUG: Loaded contents of /opt/aws/opsworks/releases/20131107153140_213/site-cookbooks/python/providers/pip.rb into a provider named python_pip defined in Chef::Provider::PythonPip
DEBUG: Loading cookbook python's providers from /opt/aws/opsworks/releases/20131107153140_213/site-cookbooks/python/providers/virtualenv.rb
INFO: PythonVirtualenv light-weight provider already initialized -- overriding!
Aber wenn ich versuche, python_pip zu verwenden, erhalte ich eine Fehlermeldung:
ERROR: Caught exception while compiling OpsWorks custom run list: NameError - Cannot find a resource for python_pip on ubuntu version 12.04
Ich habe versucht, hinzuzufügen depends "python"
in meiner metadata.rb, aber das hat nicht geholfen.Alle Vorschläge sind willkommen.
Meine Verzeichnisstruktur meines Kochbuchs „Python“:
.
├── python
│ ├── attributes
│ │ └── default.rb
│ ├── metadata.rb
│ ├── providers
│ │ ├── pip.rb
│ │ └── virtualenv.rb
│ ├── recipes
│ │ ├── default.rb
│ │ ├── django.rb
│ │ ├── package.rb
│ │ ├── pip.rb
│ │ ├── source.rb
│ │ └── virtualenv.rb
│ ├── specs
│ │ └── configure_spec.rb
│ └── templates
│ └── default
└── README.md
Lösung
Versuchen Sie nicht, das Python-Kochbuch zu ändern, es sei denn, es erfüllt nicht bereits das, was Sie benötigen.Ihr Kochbuchverzeichnis sollte mindestens so aussehen:
cookbooks/
├─python/ <clone of https://github.com/poise/python>
|
└─application_cookbook/
├─recipes/
| └─default.rb <containing the resource declaration you have in the question>
└─metadata.rb <with a `depends "python"` statement in it>
Das war's, das Python-Kochbuch muss nicht geändert werden.Stellen Sie jetzt einfach Ihre Runlist auf ein [ "python", "application_cookbook" ]
und schon kann es losgehen.
Andere Tipps
Bevor Sie das verwenden können python_pip
LWRP, Sie müssen entweder Python in Ihrer Runlist haben oder include_recipe "python"
innerhalb Ihres eigenen Rezepts.
Hier ist ein Beispiel, das davon ausgeht, dass Sie einen Benutzernamen haben dj
mit bereits eingerichtetem Home-Verzeichnis.
# Note that the recipe will install Python, setuptools and pip
include_recipe "python"
# Create a virtual environment
python_virtualenv '/home/dj/virtenv' do
interpreter "python2.7"
owner 'dj'
group 'dj'
action :create
end
# Install Django to a virtualenv
python_pip "django" do
virtualenv '/home/dj/virtenv'
user 'dj'
group 'dj'
action :install
end