create virtualenv with pip modle and centos scl (rh-python36)

Hi all,

I’m trying to solve following problem.

I need to create virtualenv for python using centos scl rh-python36

Manual way is easy, there are several way how to do that

    /opt/rh/rh-python36/root/bin/python -m venv env
    . ./env/bin/activate
    pip install -U pip setuptools
    pip install -t requirements.txt

But but with ansible I’m a little bit lost.

  - name: create virtualenv
    pip:
      virtualenv: "{{ haproxy_tools_remote_dir }}/{{ haproxy_tools_version }}/env"
      virtualenv_python: "/opt/rh/{{ haproxy_tools_scl_python }}/root/bin/python"
      requirements: "{{ haproxy_tools_remote_dir }}/{{ haproxy_tools_version }}/requirements.txt"
    tags:
      - debug

The output is
fatal: [lb01.test.host.sk]: FAILED! => {"changed": false, "msg": "No setuptools found in remote host, please install it first.”}

Any idea, please ?

  regards
    Peter

I believe the problem is that the system python at /usr/bin/python doesn’t have python-setuptools installed

You would need to either install python-setuptools via yum, or set ansible_python_interpreter to /opt/rh/rh-python36/root/bin/python so that ansible is using that SCL python also.

By default ansible will use /usr/bin/python on the remote, and use that to configure the virtualenv, but configure the virtualenv to use the SCL python. So basically ansible is using 1 python to run another.