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


Vagrantfile.include

# -*- mode: ruby -*-
# vi: set ft=ruby :

module MyVars

ENV["BRIDGE"] = "eno1"

systems = {
        'host1' => '',
        'host2' => '',
        'host3' => '',
        }
end

-- 
This mailing list is governed under the HashiCorp Community Guidelines - 
https://www.hashicorp.com/community-guidelines.html. Behavior in violation of 
those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
--- 
You received this message because you are subscribed to the Google Groups 
"Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vagrant-up/a38953eb-d2a2-44b8-9113-adcbfc84c478%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to