Pergunta

My Vagrantfile looks like this (some parts are missing):

Vagrant.configure("2") do |config|    
    # Provisioning
    config.vm.provision :chef_solo do |chef|
        chef.cookbooks_path = ["provisioning/chef/cookbooks"]
        chef.log_level = :debug
        chef.run_list = ["recipe[python]"]
    end
end

According to Opscode python recipe Readme, it is possible to install python package with a python_pip command and python virtualenvs with a python_virtualenv command. How Can I integrate them in my Vagrantfile?

Foi útil?

Solução

The pip and virtualenv are already included as part of python's default recipe. By specifying recipe[python] you effectively loaded recipe recipe[python::default] which includes respective install method, pip and virtualenv.

In order to use python_pip and python_virtualenv providers (as name suggest they provide the functionality) you just add them to your custom application recipe like suggested in cookbook's README file

python_pip "gunicorn"

python_virtualenv "/home/ubuntu/my_cool_ve" do
  owner "ubuntu"
  group "ubuntu"
  action :create
end

you need to create own cookbook/recipe. I would recommend to first understand the logic of the cookbooks, but if you want a kick start you can use something like

cd to/your/cookbooks/directory
mkdir mycookbook
cd mycookbook
mkdir recipes
touch README.md
cat >recipes/default.rb <<-EOF
# create sample directory
directory "/tmp/xx"

python_pip "gunicorn"

python_virtualenv "/home/ubuntu/my_cool_ve" do
  owner "ubuntu"
  group "ubuntu"
  action :create
end

EOF

and add this cookbook to run list recipe[mycookbook].

    chef.run_list = ["recipe[python]", "recipe[mycookbook]"]

Don't forget to check resources like Cookbooks and Getting started with Chef

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top