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!
Frank Wiles
Founder of REVSYS, Django Steering Council, PSF Fellow, and former President of the Django Software Foundation .
Expert in building, scaling and maintaining complex web applications. Want to reach out? Contact me here or use the social links below.
Join my newsletter!
Get the occasional email from me when I write something new.
Struggling with architecture decisions or team dynamics? Ask me any tech, business process, or entrepreneurial question, and I'll do my best to help!