LinuxCommandLibrary

fabric

Python SSH automation and deployment tool

TLDR

Run command on remote host

$ fab -H [host] -- [command]
copy
Run task from fabfile
$ fab [taskname]
copy
Run task on specific host
$ fab -H [user@host] [taskname]
copy
List available tasks
$ fab --list
copy
Run with specific identity file
$ fab -i [~/.ssh/key] -H [host] [taskname]
copy

SYNOPSIS

fab [options] [task[:arg,...]]...

DESCRIPTION

Fabric is a Python library and command-line tool for executing shell commands on remote servers over SSH. It simplifies deployment, system administration, and automation tasks.
Tasks are defined in a fabfile.py using Python. Fabric 2.x provides a cleaner API than version 1.x, with Connection objects and a simpler task decorator.

PARAMETERS

-H, --hosts hosts

Comma-separated host list.
-i key
SSH identity file.
-u, --user user
SSH username.
-l, --list
List available tasks.
-p, --password
Prompt for SSH password.
-d task
Show task docstring.
-- command
Run shell command directly.
-c, --config file
Config file path.
-r, --roles roles
Roles to operate on.

FABFILE EXAMPLE

$ from fabric import task

@task
def deploy(c):
    c.run("git pull")
    c.run("pip install -r requirements.txt")
    c.run("systemctl restart myapp")

@task
def uptime(c):
    c.run("uptime")
copy

CAVEATS

Version 2.x is significantly different from 1.x. Requires SSH access. Python 3 required for Fabric 2+. Complex deployments may benefit from Ansible or similar tools.

HISTORY

Fabric was created by Jeff Forcier in 2009 as a simpler alternative to Capistrano for Python deployments. Version 2.0, released in 2018, was a complete rewrite with a modernized API.

SEE ALSO

ansible(1), paramiko(1), ssh(1), invoke(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community