FrankWiles.com

SaltStack and multiple pip requirements files

Say you have requirements files that are setup like this:

# /home/code/requirements/base.pip
Django==1.5.1
# /home/code/requirements/prod.pip

-r base.pip
psycopg2==2.5.1

Which is not only a very common setup, but also a best practice in the Python community.

Unfortunately, this doesn’t work out of the box with SaltStack. If you setup a managed virtual environment like this:

# Setup virtualenv
/home/code/virtualenv:
    virtualenv.managed:
        - distribute: True
        - runas: my_code_user
        - requirements: /home/code/src/requirements/prod.pip

You get the following error:

Could not open requirements file: [Errno 2] No such file or directory: '/tmp/base.pip'

This happens because Salt ends up moving this file to /tmp to help with chowning the entire venv when it’s finished. To get around this issue you just need to add:

no_chown: True

to your Salt state like so:

# Setup virtualenv
/home/code/virtualenv:
    virtualenv.managed:
        - distribute: True
        - runas: my_code_user
        - requirements: /home/code/src/requirements/prod.pip
        - no_chown: True

Related GitHub issues:

Hope this helps!

Posted 04 November 2013