• Stars
    star
    185
  • Rank 208,271 (Top 5 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 11 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Enables Vagrant to ssh into and provision managed servers

Vagrant ManagedServers Provider

Build Status

This is a Vagrant 1.6+ plugin that adds a provider for "managed servers" to Vagrant, i.e. servers for which you have SSH access but no control over their lifecycle.

Since you don't control the lifecycle:

  • up and destroy are re-interpreted as "linking" / "unlinking" vagrant with a managed server
  • once "linked", the ssh, provision and share commands work as expected, and status shows the managed server as either "running" or "not reachable"
  • reload will issue a reboot command on the managed server (cross your fingers ;-))
  • halt, suspend and resume are no-ops in this provider

Credits: this provider was initially based on the vagrant-aws provider with the AWS-specific functionality stripped out.

Features

  • SSH into managed servers.
  • Provision managed servers with any built-in Vagrant provisioner.
  • Reboot a managed server.
  • Synced folder support.
  • Provide access to a managed server via Vagrant Share.

Usage

Install using the standard Vagrant plugin installation method:

$ vagrant plugin install vagrant-managed-servers

In the Vagrantfile you can now use the managed provider and specify the managed server's hostname and credentials:

Vagrant.configure("2") do |config|
  config.vm.box = "tknerr/managed-server-dummy"

  config.vm.provider :managed do |managed, override|
    managed.server = "foo.acme.com"
    override.ssh.username = "bob"
    override.ssh.private_key_path = "/path/to/bobs_private_key"
  end
end

Next run vagrant up --provider=managed in order to "link" the vagrant VM with the managed server:

$ vagrant up --provider=managed
Bringing machine 'default' up with 'managed' provider...
==> default: Box 'tknerr/managed-server-dummy' could not be found. Attempting to find and install...
    default: Box Provider: managed
    default: Box Version: >= 0
==> default: Loading metadata for box 'tknerr/managed-server-dummy'
    default: URL: https://vagrantcloud.com/tknerr/managed-server-dummy
==> default: Adding box 'tknerr/managed-server-dummy' (v1.0.0) for provider: managed
    default: Downloading: https://vagrantcloud.com/tknerr/managed-server-dummy/version/1/provider/managed.box
    default: Progress: 100% (Rate: 122k/s, Estimated time remaining: --:--:--)
==> default: Successfully added box 'tknerr/managed-server-dummy' (v1.0.0) for 'managed'!
==> default: Linking vagrant with managed server foo.acme.com
==> default:  -- Server: foo.acme.com

Once linked, you can run vagrant ssh to ssh into the managed server or vagrant provision to provision that server with any of the available vagrant provisioners:

$ vagrant provision
...
$ vagrant ssh
...

In some cases you might need to reboot the managed server via vagrant reload:

$ vagrant reload
==> default: Rebooting managed server foo.acme.com
==> default:  -- Server: foo.acme.com
==> default: Waiting for foo.acme.com to reboot
==> default: Waiting for foo.acme.com to reboot
==> default: Waiting for foo.acme.com to reboot
==> default:  foo.acme.com rebooted and ready.

If you are done, you can "unlink" vagrant from the managed server by running vagrant destroy:

$ vagrant destroy -f
==> default: Unlinking vagrant from managed server foo.acme.com
==> default:  -- Server: foo.acme.com

If you try any of the other VM lifecycle commands like halt, suspend, resume, etc... you will get a warning that these commands are not supported with the vagrant-managed-servers provider.

Box Format

Every provider in Vagrant must introduce a custom box format. This provider introduces a "dummy box" for the managed provider which is really nothing more than the required metadata.json with the provider name set to "managed".

You can use the tknerr/managed-server-dummy box like that:

Vagrant.configure("2") do |config|
  config.vm.box = "tknerr/managed-server-dummy"
  ...
end

Configuration

This provider currently exposes only a single provider-specific configuration option:

  • server - The IP address or hostname of the existing managed server

It can be set like typical provider-specific configuration:

Vagrant.configure("2") do |config|
  # ... other stuff

  config.vm.provider :managed do |managed|
    managed.server = "myserver.mydomain.com"
  end
end

Networks

Networking features in the form of config.vm.network are not supported with vagrant-managed-servers. If any of these are specified, Vagrant will emit a warning and just ignore it.

Synced Folders

There is minimal synced folders support for provisioning linux guests via rsync, and for windows guests via either smb, winrm or rsync (see below).

This is good enough for all built-in Vagrant provisioners (shell, chef, and puppet) to work!

Windows support

It is possible to use this plugin to control pre-existing windows servers using WinRM instead of rsync, with a few prerequisites:

  • WinRM installed and running on the target machine
  • The account used to connect is a local account and also a local administrator (domain accounts don't work over basic auth)
  • WinRM basic authentication is enabled
  • WinRM unencrypted traffic is enabled

For more information, see the WinRM Gem Troubleshooting Guide

Your vagrantfile will look something like this:

config.vm.define 'my-windows-server' do |windows|
  windows.vm.communicator = :winrm
  windows.winrm.username = 'vagrant'
  windows.winrm.password = 'vagrant'
  windows.vm.provider :managed do |managed, override|
    managed.server = 'myserver.mydomain.com'
  end
end

Synced Folders (Windows)

It is recommended that you install the vagrant-winrm-syncedfolders plugin for communicating with Windows guests (vagrant plugin install vagrant-winrm-syncedfolders). Once installed, Vagrant Managed Servers will try several different mechanisms to sync folders for Windows guests. In order of priority:

  1. SMB - requires running from a Windows host, an Administrative console, and Powershell 3 or greater. Note that there is a known bug which causes the Powershell version check to hang for Powershell 2
  2. WinRM - uses the WinRM communicator and is reliable, but can be slow for large numbers of files.
  3. RSync - requires rsync.exe installed and on your path.

Vagrant will try to use the best folder synchronization mechanism given your host and guest capabilities, but you can force a different type of folder sync with the type parameter of the synced_folder property in your Vagrantfile.

windows.vm.synced_folder '.', '/vagrant', type: "winrm"

Development

To work on the vagrant-managed-servers plugin, clone this repository out, and use Bundler to get the dependencies:

$ bundle

Once you have the dependencies, verify the unit tests pass with rake:

$ bundle exec rake

If those pass, you're ready to start developing the plugin. You can test the plugin without installing it into your Vagrant environment by using the Vagrantfile in the top level of this directory and use bundler to execute Vagrant.

First, let's pretend we have a managed server by bringing up the local_linux vagrant VM with the default virtualbox provider:

$ bundle exec vagrant up local_linux

Now you can use the managed provider (defined in a separate VM named managed_linux) to ssh into or provision the actual managed server:

$ # link vagrant with the server
$ bundle exec vagrant up managed_linux --provider=managed
$ # ssh / provision
$ bundle exec vagrant ssh managed_linux
$ bundle exec vagrant provision managed_linux
$ # unlink
$ bundle exec vagrant destroy managed_linux

More Repositories

1

bills-kitchen

All you need for cooking with Chef and Vagrant on Windows you will find in Bill's Kitchen
Ruby
131
star
2

vagrant-docker-baseimages

A collection of Vagrant-friendly docker base images
Ruby
55
star
3

sample-infrastructure-repo

sample infrastructure repository based on vagrant and application cookbooks
Ruby
16
star
4

linus-kitchen

An Ubuntu-based developer VM for hacking with Chef, Vagrant, Docker & Co
Ruby
16
star
5

sample-toplevel-cookbook

A sample "top-level" cookbook hosting a website
Ruby
10
star
6

circleci-redirector

Extends the CircleCI REST API with bookmarkable URLs for latest build and build artifacts
Ruby
10
star
7

vagrant-plugin-bundler

This plugin checks a list of requirements against the installed plugins
Ruby
9
star
8

jenkins-pipes-infra

Infrastructure (i.e. a dockerized Jenkins) and overview for the Jenkins Pipes demo
9
star
9

jenkins-pipes-helloworld

Example project with a Jenkinsfile for the Jenkins Pipes demo
Shell
9
star
10

vagrant-appveyor-testing

Repo for testing stuff on AppVeyor
7
star
11

vagrant-toplevel-cookbooks

downloads and installs the per-node top-level cookbooks in chef-solo based infrastructures
Ruby
6
star
12

cookbooks-vagrant-ohai

the vagrant-ohai recipe borrowed from agoddard/street-chef
Ruby
4
star
13

jenkins-pipes-jobs

Jobs Repository for the Jenkins Pipes demo
Groovy
3
star
14

vagrant-baseboxes

Veewee Definitions and Rakefile for building Vagrant Baseboxes
Ruby
3
star
15

sample-ejb-app

Sample WebApp using EJBs
Java
2
star
16

vagrant-workflow-tests

Specs for my Vagrant / Chef Solo based workflow
Ruby
2
star
17

bills-kitchen-repo

Chef repository being used in Bill's Kitchen
Ruby
1
star
18

vagrant-proxy-test

fiddling around with Vagrant and HTTP Proxies
Shell
1
star
19

cookbooks-motd

Chef cookbook for setting the MOTD via /etc/motd
Ruby
1
star
20

aurelia-todo-app

Playground repository for playing with Aurelia
TypeScript
1
star