Best way to add an environment variable in fabric?
As of fabric 1.5 (released), fabric.context_managers.shell_env does what you want. with shell_env(FOO1=’BAR1′, FOO2=’BAR2′, FOO3=’BAR3′): local(“echo FOO1 is $FOO1”)
As of fabric 1.5 (released), fabric.context_managers.shell_env does what you want. with shell_env(FOO1=’BAR1′, FOO2=’BAR2′, FOO3=’BAR3′): local(“echo FOO1 is $FOO1”)
Yes, you can run fab locally by using method local instead of run. What I do typically is have methods for setting up the environment, and call these methods first before calling the actual task. Let me illustrate this with an example for your specific question fabfile.py from fabric.operations import local as lrun, run from … Read more
Get the container ID and run the command. docker exec -it container_id python manage.py createsuperuser
Try passing shell=False to sudo. That way /bin/bash won’t be added to the sudo command. sudo(‘some_command’, shell=False) From line 503 of fabric/operations.py: if (not env.use_shell) or (not shell): real_command = “%s %s” % (sudo_prefix, _shell_escape(command)) the else block looks like this: # V– here’s where /bin/bash is added real_command = ‘%s %s “%s”‘ % (sudo_prefix, … Read more
Current advice It seems there is already official support for Python 3.4+ in Fabric v2+ and I guess it should be preferred although there may be some incompatible changes. So in an ideal world, nobody should have this problem anymore 🙂 pip3 install -U “fabric>2.0” Maintained old API in Python 3 Because some people were … Read more
“Best practices” are very context-dependent, so I won’t claim my practices are best, just that they work for me. I work on mostly small sites, so no multiple-server deployments, CDNs etc. I do need to support Webfaction shared hosting deployment, as some clients need the cheapest hosting they can find. I do often have to … Read more
You can prevent aborting on non-zero exit codes by using the settings context manager and the warn_only setting: from fabric.api import settings with settings(warn_only=True): result = run(‘pngout old.png new.png’) if result.return_code == 0: do something elif result.return_code == 2: do something else else: #print error to user print result raise SystemExit() Update: My answer is … Read more
You can use put for that as well (at least in 1.0.0): local_path may be a relative or absolute local file or directory path, and may contain shell-style wildcards, as understood by the Python glob module. Tilde expansion (as implemented by os.path.expanduser) is also performed. See: http://docs.fabfile.org/en/1.0.0/api/core/operations.html#fabric.operations.put Update: This example works fine (for me) on … Read more
Since version 1.4.0, Fabric uses your ssh config (partly). However, you need to explicitly enable it, with env.use_ssh_config = True somewhere near the top of your fabfile. Once you do this, Fabric should read your ssh config (from ~/.ssh/config by default, or from env.ssh_config_path). One warning: if you use a version older than 1.5.4, an … Read more
From the docs: … Fabric defaults to a “fail-fast” behavior pattern: if anything goes wrong, such as a remote program returning a nonzero return value or your fabfile’s Python code encountering an exception, execution will halt immediately. This is typically the desired behavior, but there are many exceptions to the rule, so Fabric provides env.warn_only, … Read more