-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
should allow extend Vagrantfile with Vagrantfile-ext.rb #246
Comments
hoatle
changed the title
should allow extend Vagrantfile with Vagrantfile-override
should allow extend Vagrantfile with Vagrantfile-ext.rb
Feb 9, 2017
the use case is: now I want to use https://github.com/devopsgroup-io/vagrant-hostmanager but it's impossible for now (waits for #186). Luckily, it's possible now with Vagrantfile-ext.rb I just need to create Vagrantfile-ext.rb with the following content: # -*- mode: ruby -*-
# vi: set ft=ruby :
# we want to resemble the code from the Vagrantfile file
# users adjust the settings here
plugins = [{
'_id' => '0',
'name' => 'vagrant-hostmanager',
'config_key' => 'hostmanager',
'required' => true,
'enabled' => true,
'manage_host' => true,
'manage_guest' => true,
'ignore_private_ip' => true
}]
# this is not supposed to be edited by users
Vagrant.configure('2') do |config|
plugins.each do |plugin|
plugin_name = plugin['name']
if plugin['required'] == true
unless Vagrant.has_plugin?(plugin_name)
puts red("required: '$ vagrant plugin install #{plugin_name}'")
exit!
end
end
if Vagrant.has_plugin?(plugin_name) and plugin.key?('config_key')
config_key = plugin['config_key']
if 'hostmanager' == config_key
unless plugin['enabled'].nil?
config.hostmanager.enabled = plugin['enabled']
end
unless plugin['manage_host'].nil?
config.hostmanager.manage_host = plugin['manage_host']
end
unless plugin['manage_guest'].nil?
config.hostmanager.manage_guest = plugin['manage_guest']
end
unless plugin['ignore_private_ip'].nil?
config.hostmanager.ignore_private_ip = plugin['ignore_private_ip']
end
unless plugin['include_offline'].nil?
config.hostmanager.include_offline = plugin['include_offline']
end
unless plugin['aliases'].nil?
config.hostmanager.aliases = plugin['aliases']
end
# workaround for :public_network
config.hostmanager.ip_resolver = proc do |vm, resolving_vm|
read_ip_address(vm)
end
end
end
end
end
# thanks to https://github.com/devopsgroup-io/vagrant-hostmanager/issues/121#issuecomment-69050265
$logger = Log4r::Logger.new('Vagrantfile-ext')
def read_ip_address(machine)
command = "LANG=en ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1 }'"
result = ""
$logger.info "Processing #{ machine.name } ... "
begin
# sudo is needed for ifconfig
machine.communicate.sudo(command) do |type, data|
result << data if type == :stdout
end
$logger.info "Processing #{ machine.name } ... success"
rescue
result = "# NOT-UP"
$logger.info "Processing #{ machine.name } ... not running"
end
# the second inet is more accurate
result.chomp.split("\n").last
end and it should work. |
hoatle
added a commit
to hoatle/teracy-dev
that referenced
this issue
Feb 9, 2017
hoatle
added a commit
to hoatle/teracy-dev
that referenced
this issue
Feb 9, 2017
hoatle
added a commit
to hoatle/teracy-dev
that referenced
this issue
Feb 9, 2017
….rb: support to load more extension files
hoatle
added a commit
that referenced
this issue
Feb 9, 2017
@ #246 | should allow extend Vagrantfile with Vagrantfile-ext.rb
This was referenced Jul 13, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using vagrant_config_override.json is for normal users.
With Vagrantfile-ext.rb, we can give users power users to customize at the highest level.
This is required when vagrant_config.json is not enough to customize the VM.
Related: https://groups.google.com/forum/#!topic/vagrant-up/g68oH8-JrCE
For example, now users want to use https://github.com/devopsgroup-io/vagrant-hostmanager it's impossible with vagrant_config_override.json
Note: users are only allowed to use vagrant_config_override.json to customize the vagrant config for now.
Use Vagrantfile-ext.rb if available. Note: don't use this if you don't know what you're going to do, usually using vagrant_config_override.json is enough in most cases.
Note: allows users to choose the path and the name for Vagrantfile-override on the vagrant_config_override.json file.
The loading order:
And users can optionally add vagrant_config_ext.json, vagrant_config_ext_override.json if they want, however, this is rather complicated, don't do this if you don't know what you're going to do.
When this issue is resolved, users can use Vagrantfile-ext.rb.
The text was updated successfully, but these errors were encountered: