skip to Main Content

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


  1. 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 :

    python_runtime '3' do
      version 3
      action :install
    end
    

    And then you can install your package via :

    python_package 'datadog-checks-dev[cli]'
    
    Login or Signup to reply.
  2. I assume you are running chef as root user, so you should be able to get rid of all the sudos and multipe execute statements and just execute everything in one execute or bash resource or even better: use the package 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 the bash environment, so you probably want to use a bash chef resource. Depending on how scl works, you may have to provide the ride “flag” attribute.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search