gpt4 book ai didi

linux - 使用 vagrant 和 chef-solo provisioner 安装 django

转载 作者:太空宇宙 更新时间:2023-11-04 10:48:41 24 4
gpt4 key购买 nike

作为绝对的 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 Recipe :

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 Recipe :

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 tutorial 并尝试将其翻译成 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

关于linux - 使用 vagrant 和 chef-solo provisioner 安装 django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31991282/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com