Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm attempting to install psycopg2 into a Python virtualenv with Ansible's pip module, but I need to prepend an entry to PATH for it to build correctly (it needs to know the path to the directory containing pg_config). I see that I can pass environment to the pip module, but I'm unsure of how to prepend rather than overwrite PATH.

Here I'm attempting to prepend the path with the necessary directory, but it overwrites the virtualenv PATH and fails:

- pip: name=psycopg2 virtualenv=/path/to/my/venv
    PATH: /usr/pgsql-9.3/bin:$PATH
share|improve this question

1 Answer 1

up vote 4 down vote accepted

You want to do the following:

- pip: name=psycopg2 virtualenv=/path/to/my/venv
    PATH: /usr/pgsql-9.3/bin:{{ lookup('env', 'PATH') }}

This basically accesses the PATH variable of the workstation where you are running your Ansible script from.

or if you are using Ansible 1.4 or later (which I recommend) you can also access the remote PATH env variable:

- pip: name=psycopg2 virtualenv=/path/to/my/venv
    PATH: /usr/pgsql-9.3/bin:{{ ansible_env.PATH }}
share|improve this answer
The ansible_env.PATH option was what I needed — worked perfectly. Thanks! –  Collin Allen Feb 21 at 4:56
Note that this takes the PATH of the workstation, not the server! –  vdboor Mar 12 at 8:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.