-
-
Save ozbillwang/cbc79a477af4a25bda2e to your computer and use it in GitHub Desktop.
This Vagrantfile works with an external data file (a YAML file, named servers.yaml) to create multiple Vagrant boxes easily. The servers.yaml file contains all the specifics and can be easily edited to change the number and type of boxes to create. The Vagrantfile remains unchanged. http://blog.scottlowe.org/2014/10/22/multi-machine-vagrant-with…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: coreos-01 | |
box: coreos-alpha | |
ram: 512 | |
ip: 172.17.8.101 | |
- name: coreos-02 | |
box: coreos-alpha | |
ram: 512 | |
ip: 172.17.8.102 | |
- name: coreos-03 | |
box: coreos-alpha | |
ram: 512 | |
ip: 172.17.8.103 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# # vi: set ft=ruby : | |
# Specify minimum Vagrant version and Vagrant API version | |
Vagrant.require_version ">= 1.6.0" | |
VAGRANTFILE_API_VERSION = "2" | |
# Require YAML module | |
require 'yaml' | |
# Read YAML file with box details | |
servers = YAML.load_file('servers.yaml') | |
# Create boxes | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
# Iterate through entries in YAML file | |
servers.each do |servers| | |
config.vm.define servers["name"] do |srv| | |
srv.vm.box = servers["box"] | |
srv.vm.network "private_network", ip: servers["ip"] | |
srv.vm.provider :virtualbox do |vb| | |
vb.name = servers["name"] | |
vb.memory = servers["ram"] | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Was loosing my mind getting the right yaml syntax for the Vagrant loop. Thanks, you get a star!