Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible - Virtualenv executable not found when trying python3.5

Is there a way to fix the pip module not being able to find the right python version? The key issue seems to be with virtualenv_python

- name: Create venv and install requirements
  pip:
    requirements: /home/admin/dev/python/filepro/requirements.txt
    virtualenv: /home/admin/venvs/filepro
    virtualenv_python: python3.5
  tags:
    - venv

The error:

Error message:
FAILED! => {"changed": false, "failed": true, "msg": "Failed to find required executable virtualenv"}

/usr/bin/python3.5 is where python 3.5 is and I'm using Ansible 2.2.1.0

like image 999
Jim Factor Avatar asked Dec 02 '22 12:12

Jim Factor


1 Answers

First, you need to make sure virtualenv is installed for the version of Python you intend to use. You can do that prior running the pip module by:

- name: Install virtualenv via pip
  pip:
    name: virtualenv
    executable: pip3

If you don't want (or cannot) install virualenv as root, Ansible will fail to pick up the virtualenv executable. You can add it manually to the PATH environmental variable:

- name: Create venv and install requirements
  pip:
    requirements: /home/admin/dev/python/filepro/requirements.txt
    virtualenv: /home/admin/venvs/filepro
    virtualenv_python: python3.5
  tags:
    - venv
  environment:
    PATH: "{{ ansible_env.PATH }}:{{ ansible_user_dir }}/.local/bin"

Alternatively, you can install vitualenv as a root user:

- name: Install virtualenv via pip
  pip:
    name: virtualenv
    executable: pip3
  become: yes
  become_user: root
like image 174
rlat Avatar answered Dec 05 '22 14:12

rlat