Skip to content

Instantly share code, notes, and snippets.

@craigafinch
Forked from alexaivars/fabfile.py
Last active September 25, 2017 10:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save craigafinch/b699c46ecd9b6bfe5f48 to your computer and use it in GitHub Desktop.
Save craigafinch/b699c46ecd9b6bfe5f48 to your computer and use it in GitHub Desktop.
Use fabric with a vagrant instance
from fabric.api import env, local, run
def vagrant():
"""USAGE:
fab vagrant uname
Note that the command to run Fabric might be different on different
platforms.
"""
# change from the default user to 'vagrant'
env.user = 'vagrant'
# connect to the port-forwarded ssh
env.hosts = ['127.0.0.1:2222']
# find running VM (assuming only one is running)
result = local('vagrant global-status | grep running', capture=True)
machineId = result.split()[0]
# use vagrant ssh key for the running VM
result = local('vagrant ssh-config {} | grep IdentityFile'.format(machineId), capture=True)
env.key_filename = result.split()[1]
def uname():
run('uname -a')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment