Fabric does not pass the environment to a local shell like Invoke does
See original GitHub issueConsider this task definition, saved as both fabfile.py
and tasks.py
:
from invoke import task
@task
def make(c):
c.run('env')
fab make
outputs:
PWD=/tmp
SHLVL=1
_=/usr/bin/env
inv make
outputs:
LC_ALL=en_US.UTF-8
NVM_DIR=/home/justinas/.nvm
LC_MEASUREMENT=en_US.UTF-8
LC_PAPER=en_US.UTF-8
LC_MONETARY=en_US.UTF-8
<...> (lots of stuff in my environment)
I initially found this when trying to use fpm which checks the PATH
variable to check that the executables it requires to function exist:
from invoke import task
@task
def make(c):
c.run('fpm -s dir -t rpm -C dist --name somename .')
This works with invoke, but not with fab.
justinas@js:/tmp$ fab make
{:timestamp=>"2018-05-11T13:11:26.218874+0300", :message=>"Need executable 'rpmbuild' to convert dir to rpm", :level=>:error}
justinas@js:/tmp$ inv make
{:timestamp=>"2018-05-11T13:11:29.967762+0300", :message=>"Created package", :path=>"somename-1.0-1.x86_64.rpm"}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:14 (4 by maintainers)
Top Results From Across the Web
How to set environment variables using Fabric - Stack Overflow
You can use fabric.context_managers.shell_env to export a variable to bash for your shell and all subshells spawned from it - but those ...
Read more >The environment dictionary, env - Fabric documentation
Most of Fabric's behavior is controllable by modifying env variables, such as env.hosts (as seen in the tutorial). Other commonly-modified env vars include:....
Read more >Fabric - Read the Docs
Invoke implements CLI parsing, task organization, and shell command execution (a generic framework plus specific implementation for local ...
Read more >Fabric Automation - Peterlog
The Fabric library and executable are used for remote execution of tasks, just like the invoke lib are used for local tasks. Installation....
Read more >Shell Variables - Learning the bash Shell, Second Edition [Book]
Some environment variables are predefined by the shell when you log in. ... whose value is the name of the script (i.e., the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@justinas I ended up using run from invoke for local tasks, I import it like this:
I just ran into this as well. I was doing
c.run('make build')
and none of my ENV pulled through (specifically GOPATH which caused the build to fail). Adding thereplace_env=False
fixed it.Edit: I see according to the docs:
It was just a bit confusing to me since I was trying to run a local command.