2 What is the proper way to execute a requirements.txt file in a chef cookbook recipe to install python modules?

question created at Sat, Jun 1, 2019 12:00 AM

I am trying to learn chef and very new at it.

I have a requirements.txt file which I'm trying to execute through a chef recipe to install some Python modules. I have tried different variations of the code, however I feel like I'm missing something. I have tried writing the following code in the chef recipe:

template '/etc' do
  source 'requirements.txt.erb'
  owner 'root'
  group 'root'
  mode '0644'
end

execute 'requirements.txt' do
  command 'pip install -r requirements.txt'
  action  'run'
end 

I was expecting that the requirements file will be called when I run vagrant up and the modules/dependencies of the app will be installed. However, I get this error:

Error executing action run on resource 'execute[requirements.txt]'

1
2 Answers 2

Check this example from https://docs.chef.io/resource_execute.html

execute 'upgrade script' do
   command 'php upgrade-application.php && touch /var/application/.upgraded'
   creates '/var/application/.upgraded'
   action :run
end

You need to specify the run action as shown above (:run) rather than with single quotes as shown in your posted example.

0
2019-06-03 22:53:10Z

if i am not mistaken, i think that coderanger developed a cookbook named python-poise, which has pip_requirements chef resource. it looks like:

pip_requirements '/opt/myapp/requirements.txt'
0
2019-06-06 04:38:59Z
source placed here