Skip to content

Instantly share code, notes, and snippets.

@muhammad-ammar
Forked from aubricus/__init__.py
Created March 4, 2020 22:18
Show Gist options
  • Save muhammad-ammar/414b7fda25584eb99320951cacff26f7 to your computer and use it in GitHub Desktop.
Save muhammad-ammar/414b7fda25584eb99320951cacff26f7 to your computer and use it in GitHub Desktop.
Using Fabric to connect to the remote server via an ssh config.
from fabric.api import env
env.use_ssh_config = True
env.forward_agent = True
env.roledefs = {
# key # hostname from config
'foo': ['foo.production'],
}
ForwardAgent yes
Host foo.production
User username
HostName foo.com
IdentityFile /path/to/.ssh/keyname_rsa
from fabric.api import local, run, task, roles
@task
def local_uname():
local('uname -a')
@roles('foo')
@task
def remote_uname():
run('uname -a')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment