Skip to content

Instantly share code, notes, and snippets.

@gcmalloc
Last active January 2, 2016 23:09
Show Gist options
  • Save gcmalloc/8374180 to your computer and use it in GitHub Desktop.
Save gcmalloc/8374180 to your computer and use it in GitHub Desktop.
from fabric.api import *
import vagrant
def with_vagrant(vm_name=None):
"""Apply the rule with the vagrant box."""
print("applying on box {}".format(vm_name))
v = vagrant.Vagrant()
if not all([status == "running" for status in v.status().values()]):
print("Vagrant is not running, starting it right now.")
v.up()
while not all([status == "running" for status in v.status().values()]):
print("Wait for vagrant to be up.")
time.sleep(1)
v_conf = v.conf(vm_name=vm_name)
ssh_key = v_conf.get('IdentityFile')
ssh_string = v.user_hostname_port(vm_name=vm_name)
env.hosts.append(ssh_string)
#env.host = ssh_string
env.key_filename = ssh_key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment