LinuxCommandLibrary

fabric

Execute commands on remote systems

TLDR

Run the setup to configure fabric

$ fabric [[-S|--setup]]
copy

List all available patterns
$ fabric [[-l|--listpatterns]]
copy

Run a pattern with input from a file
$ fabric < [path/to/input_file] [[-p|--pattern]] [pattern_name]
copy

Run a pattern on a YouTube video URL
$ fabric [[-y|--youtube]] "[https://www.youtube.com/watch?v=video_id]" [[-p|--pattern]] [pattern_name]
copy

Chain patterns together by piping output from one to another
$ fabric [[-p|--pattern]] [pattern1] | fabric [[-p|--pattern]] [pattern2]
copy

Run a custom user-defined pattern
$ fabric [[-p|--pattern]] [custom_pattern_name]
copy

Run a pattern and save the output to a file
$ fabric [[-p|--pattern]] [pattern_name] [[-o|--output]] [path/to/output_file]
copy

Run a pattern with the specified variables
$ fabric [[-p|--pattern]] [pattern_name] [[-v|--variable]] "[variable_name]:[value]"
copy

SYNOPSIS

fab [options] [task [arg1 arg2 ...] ...]

PARAMETERS

-h, --help
    Show this help message and exit

-V, --version
    Show program's version number and exit

-l, --list
    List available tasks with descriptions

-d TASK, --display TASK
    Display detailed help for specific task

-r, --dry-run
    Print actions without executing

--graph
    Print task dependency callgraph

-c CONFIG, --config-file CONFIG
    Load config file(s); repeatable

--fabfile PATH
    Path to fabfile (default: fabfile.py)

--hosts HOSTS
    Override hosts from fabfile

--ssh-config PATH
    Custom SSH config file

DESCRIPTION

Fabric is a Python library and CLI tool for simplifying SSH-based tasks like deployments, configurations, and admin work. Users define reusable tasks in a fabfile.py Python script, executed via the fab command (fabric in some setups). It handles connections, sudo, file transfers, and parallel execution across hosts or roles.

Unlike full CM tools like Ansible, Fabric offers lightweight, Python-scriptable automation with native shell integration. Fabric 1.x (legacy) focused on fabfiles with decorators; Fabric 2.x+ (current, Python 3) uses the Invoke library for tasks, improving modularity, concurrency, and core logic separation.

Install via pip install fabric. Example fabfile:
from fabric import task
@task
def deploy(c):
    c.run('git pull')

Run: fab deploy. Ideal for DevOps scripting without agent requirements. Supports gateways, key auth, and prompts. (172 words)

CAVEATS

CLI is fab, not always fabric; requires Python 3+ and pip install fabric. No built-in manpage; tasks must be defined in fabfile.py. Fabric 1.x deprecated.

BASIC EXAMPLE

fab -H user@host deploy
Executes deploy task on remote host.

INSTALLATION

pip install fabric
Requires paramiko for SSH.

HISTORY

Created 2008 by Jeff Forcier as Fabric 1.x for SSH fabfiles. Rewritten 2016 as Fabric 2.0 by Jeff Geerling/bitprophet, integrating Invoke for better parallelism and Python 3. Fabric 3.x (2023+) enhances API stability and concurrency.

SEE ALSO

ssh(1), scp(1), rsync(1), invoke(1)

Copied to clipboard