running fabric script locally

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

Can I prevent fabric from prompting me for a sudo password?

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

Python 3 support for fabric

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

How do you use pip, virtualenv and Fabric to handle deployment?

“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

Can I catch error codes when using Fabric to run() calls in a remote shell?

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

How do I copy a directory to a remote machine using Fabric?

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

Connecting to a host listed in ~/.ssh/config when using Fabric

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

How to continue a task when Fabric receives an error

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)