from fabric import task
cmd = '''python3 -c "import os; print(os.environ.get('ENV'))"'''
@task
def test_env(ctx):
ctx.run(cmd, replace_env=False, echo=True, env={'ENV': 'production'})
@task
def test_prefix(ctx):
with ctx.prefix('ENV=production'):
ctx.run(cmd, replace_env=False, echo=True)
First task prints None because the default sshd install has AcceptEnv LANG LC_* and nothing else (see #1744 (comment)):
% fab -H example.com test-env
python3 -c "import os; print(os.environ.get('ENV'))"
None
Second one fails due to && (although it probably used to work, see #1744 (comment)):
% fab -H example.com test-prefix
ENV=production && python3 -c "import os; print(os.environ.get('ENV'))"
None
The value of replace_env flag does not matter.
First task prints
Nonebecause the default sshd install hasAcceptEnv LANG LC_*and nothing else (see #1744 (comment)):Second one fails due to
&&(although it probably used to work, see #1744 (comment)):The value of
replace_envflag does not matter.