There are two ways to do this:
- Set env.hosts at the module level, so it gets set when the fabfile is imported
- Chain modules to set the env variable.
In your case, the second one can be accomplished by removing the line prod()
from collectstatic
and instead invoking fabric like this:
fab prod collecstatic
This sort of decoupling can be immensely powerful. See here: http://fabric.readthedocs.org/en/latest/usage/execution.html#globally-via-env
To run from a specific directory, try using with cd
:
def collectstatic():
with cd(env.remote_app_dir):
run("python2.7 manage.py collectstatic --noinput")
See here: https://fabric.readthedocs.org/en/latest/api/core/context_managers.html