I have configs that must always be present in Vagrantfile, when init is run, regardless of box.
For example when I run vagrant init ubuntu/trusty64
or vagrant init centos/7
this must be present in both Vagrantfiles:
config.vm.provider "virtualbox" do |vb|
vb.memory = 2048
end
config.vm.provision "shell", inline: <<-SHELL
# obligatory provisioning goes here
SHELL
Is there any way I can configure vagrant, so that when I run vagrant init
this lines already be present in Vagrantfile?
By default you cant really change this behavior, unfortunately vagrant init
does not propose an option to use your own Vagrantfile (that would be neat but not there). There are 2 templates (see https://github.com/mitchellh/vagrant/tree/master/templates/commands/init) that can be used, the default one and a minimal one.
You're left with the following options:
Vagrantfile.erb
search the file in your system (on mac it should be somewhere in /opt/vagrant/embedded/gems/gems/vagrant-1.9.1/templates/commands/init/Vagrantfile.erb
depending your version) and change it to what you need.
You can have a global Vagrantfile
under the .vagrant.d
directory that will be applied to all your Vagrantfiles. See LOAD ORDER AND MERGING
in vagrantfile documentation.
Write a plugin with a new command to create the Vagrantfile. that is probably overkill though