pip tries to install to /usr/local/ not to my virtualenv

61 views
Skip to first unread message

Roy Smith

unread,
Dec 21, 2014, 3:50:51 PM12/21/14
to ansible...@googlegroups.com
Local setup:
ansible 1.8.2
python 2.7.1

Remote:
ansible 1.8.2
python 2.7.6
pip 1.5.4


Playbook:

---
- hosts: all
  remote_user: hyc
  vars:
    local_base_dir: "{{ lookup('env', 'VIRTUAL_ENV') }}/../.."
    remote_base_dir: "/home/hyc/hyc.org

  tasks:
  - name: create virtualenv
    pip: chdir="{{ remote_base_dir }}/deploy"
         requirements=pip-requirements
         virtualenv=python-env


When I run this playbook, my virtualenv gets created on the remote machine, but pip tries to install into the global environment, resulting in errors like:

error: could not create '/usr/local/lib/python2.7/dist-packages/django': Permission denied

It appears that the virtualenv doesn't get activated before pip starts to run.  What am I doing wrong?


--
Roy Smith



Roy Smith

unread,
Dec 21, 2014, 4:09:36 PM12/21/14
to ansible...@googlegroups.com
Hmmm, upon further investigation, I found a Stack Overflow thread (http://stackoverflow.com/questions/20040141/ansible-command-from-inside-virtualenv) which discussed this issue, and put me on the right path.  I ended up with:

  tasks:
  - name: create virtualenv
    pip: chdir="{{ remote_base_dir }}/deploy"
         virtualenv=python-env
         executable="{{ remote_base_dir }}/deploy/python-env/bin/pip"
         requirements=pip-requirements


which seems to do the right thing.  It does seem kind of counter-intuitive, however, that if you're specifying the virtualenv to install into, it doesn't, well, install into that.  Along the way to this solution, I tried the approach of two distinct pip plays, one to create the basic virtualenv, and the other to populate it with modules.  But this does the right thing in one play.

--
Roy Smith



Reply all
Reply to author
Forward
0 new messages