I’m trying to install python with chef this is the runbook
sudo yum -y install centos-release-scl
sudo yum -y install rh-python36
sudo scl enable rh-python36
The 4th step requires python 3. When I do this manually it works as expected, how ever when i do it via chef it still thinks it’s python 2.7 therefore it fails on the 4th step. How do I get around this?
execute "install centos-release-scl" do
command "sudo yum -y install centos-release-scl"
action :run
end
execute "install rh-python36" do
command "sudo yum -y install rh-python36"
action :run
end
execute "enable rh-python3" do
command "sudo scl enable rh-python36 bash"
action :run
end
execute "pip install dd-check-dev" do
command "pip install 'datadog-checks-dev[cli]'"
action :run
end
2
Answers
You might want to take a look at the poise-python community cookbook. The cookbook allows you to specify which python and pip version you want to use, and allows you to install python packages via pip using the custom resources of the cookbook. Here is sample code block for installing python 3 :
And then you can install your package via :
I assume you are running chef as
root
user, so you should be able to get rid of all thesudo
s and multipe execute statements and just execute everything in oneexecute
orbash
resource or even better: use thepackage
resource for the yum jobs.As far as I understand
scl enable
either manipulates the shell environment and/or changes symlink directions. In your example you seem to target thebash
environment, so you probably want to use abash
chef resource. Depending on howscl
works, you may have to provide the ride “flag” attribute.