Skip to content

Instantly share code, notes, and snippets.

@ragingbal
Last active March 12, 2016 21:15
Show Gist options
  • Select an option

  • Save ragingbal/1166b3459623b3f314c2 to your computer and use it in GitHub Desktop.

Select an option

Save ragingbal/1166b3459623b3f314c2 to your computer and use it in GitHub Desktop.
snippet manage vagrant using fabric
from fabric.api import env, local, run
def vagrant():
"""Allow fabric to manage a Vagrant VM/LXC container"""
env.user = 'vagrant'
v = dict(map(lambda l: l.strip().split(),local('vagrant ssh-config', capture=True).split('\n')))
# Build a valid host entry
env.hosts = ["%s:%s" % (v['HostName'],v['Port'])]
# Use Vagrant SSH key
if v['IdentityFile'][0] == '"':
env.key_filename = v['IdentityFile'][1:-1]
else:
env.key_filename = v['IdentityFile']
def uname():
"""Classic example"""
run('uname -a')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment