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

Local setup:
ansible 1.8.2
python 2.7.1

Remote:
ansible 1.8.2
python 2.7.6
pip 1.5.4

Playbook:

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.