使用 vagrant 和 chef-solo provisioner 安装 django

install django using vagrant with chef-solo provisioner

作为绝对的 Chef 初学者,我尝试使用最新的 python 和 django 设置虚拟机。我使用 "ubuntu/trusty64" 框,令我惊讶的是它的 python3 版本没有安装 pip 和 pyvenv。 所以我不得不从源代码安装最新的 python 版本 3.4.3,这似乎工作正常。但是当尝试用 chef pip install django 时,我总是得到同样的错误:

Chef::Exceptions::Package: No candidate version available for django

我的 python3 食谱:

package "python"

execute "update system" do
   command "sudo apt-get update -y"
   not_if { File.exists?('/tmp/Python-3.4.3')}
end

execute "get dependencies" do
   command "sudo apt-get install -y build-essential libbz2-dev libncurses5-dev libreadline6-dev libsqlite3-dev libgdbm-dev liblzma-dev tk8.6-dev libssl-dev python3-setuptools"
   not_if { File.exists?('/tmp/Python-3.4.3')}
end

%w[ /opt/python /djenv ].each do |path|
directory path do
    owner 'vagrant'
    group 'vagrant'
    mode '0755'
  end
end

bash 'install-python3.4.3' do
   user 'vagrant'
   cwd '/tmp'
   code <<-EOH
     set -e
     wget https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tgz
     tar -xvf Python-3.4.3.tgz
     rm Python-3.4.3.tgz
     cd Python-3.4.3
     ./configure --prefix=/opt/python
     make
     make install
     EOH
     not_if { File.exists?('/tmp/Python-3.4.3')}
end

execute "set pyvenv environment to /djenv" do
   command "/opt/python/bin/pyvenv /djenv"
   only_if{File.exists?('/opt/python/bin/python3')}
end

django 秘诀:

package 'django'

execute "activate env" do
   command "source /djenv/bin/activate"
end

execute "install django and gunicorn" do
   command "pip install gunicorn && pip install Django==1.8.3"
   not_if {File.exists('/vagrant/../manage.py')}
end

execute "deactivate" do
   command "deactivate"
end

我基本上遵循 this 教程并尝试将其翻译成 chef。

package 'python3' #will install python
package 'python3-pip' #will install pip3

execute 'pip3 install django' do #install django from command line with pip
  not_if "pip3 list | grep django" #only if it is not installed yet
end
execute 'pip3 install gunicorn' do
  not_if "pip3 list | grep gunicorn"
end