LinuxCommandLibrary

fabric

Execute commands on remote systems

TLDR

Run the setup to configure fabric

$ fabric --setup
copy

List all available patterns
$ fabric --listpatterns
copy

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

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

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

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

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

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

SYNOPSIS

fab [] [[:arg1=val1,arg2=val2,...] ...]

PARAMETERS

-f
    Specify the fabfile to use (default: fabfile.py). Can also use a colon-separated list for multiple fabfiles.

-g
    Specifies an SSH gateway to use for connections (user@host:port).

-H
    Defines a comma-separated list of remote hosts to operate on. Can also specify inline user@host or user@host:port.

-l
    Lists available tasks in the fabfile.

-n
    Disable known_hosts checking. Useful for testing but insecure.

-p
    Password for use with SSH (be careful when using this!).

-R
    Specifies a comma-separated list of roles to operate on. Roles are defined in the fabfile.

-t
    Timeout for SSH connection attempts (in seconds).

-T
    Timeout for remote commands (in seconds).

-u
    Remote username to use.

-v
    Increase verbosity (can be specified multiple times).

-V
    Show Fabric's version number and exit.

-w
    Abort execution on first error.

DESCRIPTION

Fabric is a Python library and command-line tool that streamlines the use of SSH for application deployment, system administration, or other tasks. It provides a high-level interface for executing shell commands on remote servers, transferring files, and automating repetitive operations. Fabric enables users to define tasks in Python code and then execute them across multiple servers in parallel. This makes it a powerful tool for managing infrastructure and automating deployments. Fabric relies on SSH keys for authentication to remote servers. It includes mechanisms for executing commands with sudo privileges.
Note: Fabric 1.x and 2.x are significantly different. Fabric 3 is currently under active development.

CAVEATS

Fabric's behavior can vary significantly between versions 1.x and 2.x. Make sure to consult the correct documentation for your installed version. Using passwords on the command line is generally discouraged for security reasons; SSH keys are preferred.

FABFILE STRUCTURE

A fabfile is a Python file (typically named fabfile.py) that contains the tasks you want to execute. Each task is a Python function decorated with `@task` (Fabric 2) or simply a plain function (Fabric 1). These functions can use Fabric's functions (e.g., `run`, `put`, `get`) to execute commands on remote servers.

ROLES AND HOSTS

Fabric allows you to organize your servers into roles. This is useful for targeting specific groups of servers for particular tasks. You can specify roles using the `-R` option or by defining them in your fabfile. Hosts are the individual servers you want to operate on. You can specify them using the `-H` option or by defining them within your fabfile.

CONFIGURATION

Fabric's behavior can be configured through settings in your fabfile. These settings control various aspects of the execution, such as the SSH connection settings, default user, and timeout values.

HISTORY

Fabric was initially created by Jeff Forcier as a way to automate Python deployments and other tasks. It has evolved over time, with major versions 1.x and 2.x representing significant architectural changes. Fabric 1.x gained wide adoption due to its simplicity and ease of use. Fabric 2.x was a complete rewrite, intended to provide a more robust and flexible architecture, but required significant code migration. Fabric 3 is being developed to address some limitations from fabric 2.x and to adopt the latest python tooling.

SEE ALSO

ssh(1), scp(1)

Copied to clipboard