Fabric is a high-level Python library for streamlining SSH command execution and application deployment. It is currently at version 3.2.3 and releases updates on an as-needed basis, typically for bug fixes or minor enhancements, building on Invoke and Paramiko.
pip install fabricVerified import paths — ran on the pinned version, not inferred.
Create a `fabfile.py` with tasks. Each task receives a `Connection` object `c` as its first argument. Run tasks from the command line using `fab -H user@host task_name`.
Rewrite Fabric 1.x scripts to use the new `Connection` object-based API. Consult the Fabric 2.x migration guide for details.
Access connection properties via `c.host`, `c.user`, `c.config`, etc., and call methods like `c.run()`, `c.sudo()`.
Replace calls like `run('command')` with `c.run('command')`. Similarly for `sudo`, `local`, `put`, `get`.Ensure all context manager usage is prefixed with the `Connection` object, e.g., `with c.cd('/tmp'): c.run('ls')`.Define task parameters explicitly (`@task(arg1='default')`), or configure connection parameters via `Connection` constructor, or `fab` CLI flags (`-H`, `-u`, `-i`, `-p`).
Rewrite your imports to use the new Fabric 2.x/3.x API, primarily importing `Connection`, `task`, and other components directly from the `fabric` package. For example, instead of `from fabric.api import run`, use `from fabric import Connection, task` and call methods on a `Connection` object (e.g., `c = Connection('host'); c.run('command')`).Ensure you create a `Connection` object and call `run()` or `sudo()` as methods of that object. For example, `from fabric import Connection; c = Connection('your_host'); c.run('command')`.To prevent Fabric from aborting and inspect the failure, use `with Connection(host).settings(warn_only=True): result = c.sudo('your_command')`. Then check `result.failed` or `result.return_code` to handle the error programmatically. Also, ensure the remote command is syntactically correct and the user has `sudo` privileges for it. If the error is 'sudo: cd: command not found', ensure `shell=True` (the default) is used to allow shell features like `cd` to work correctly within `sudo` calls.Verify that the SSH daemon is running on the remote server, firewalls (local and network) allow connections on port 22 (or your custom SSH port), the hostname/IP and port are correct in your Fabric `Connection` arguments, and that the remote server's SSH configuration is not explicitly denying access for your user or connection type.