I'd like to modularize my Vagrantfile. I want a main section, Vagrantfile, to be shared amongst several environments, with 'Vagrantfile.include' used for local definitions.
I've tried an endless number of solutions towards this. All have failed. Please let me know if the expectations are unrealistic here.
I have the following Vagrantfile. The 'require' and 'require_relative' reflect two of the many attempts to do this.
The Vagrantfile.include is further below. In the case of require, I get the error 'uninitialized constant MyVars'. In the case of require_relative I get 'undefined local variable or method `systems'
What would be a better approach here?
# -*- mode: ruby -*-
# vi: set ft=ruby :
BOX_IMAGE = "centos7-2018020400"
# require 'Vagrantfile.include'
require_relative 'Vagrantfile.include'
include MyVars
Vagrant.configure("2") do |config|
systems.each do |i,x|
config.vm.define vm_name = "#{i}" do |subconfig|
subconfig.vm.box = BOX_IMAGE
subconfig.ssh.username = "vagrant"
subconfig.ssh.password = "vagrant"
subconfig.vm.hostname = "#{i}"
subconfig.vm.network :public_network, auto_config: false, bridge: "#{ENV['BRIDGE']}"
subconfig.vm.provision "shell", inline: <<-SHELL
/bin/yum -y update
SHELL
subconfig.vm.provider "virtualbox" do |v|
v.name = vm_name
v.customize ["modifyvm", :id, "--paravirtprovider", "kvm"]
v.customize ["modifyvm", :id, "--autostart-enabled", "on"]
end
end
end
end