Vagrant 默认配置

标签 vagrant vagrantfile

当 init 运行时,无论盒子如何,我的配置都必须始终存在于 Vagrantfile 中。
例如,当我运行 vagrant init ubuntu/trusty64vagrant init centos/7 时,这必须出现在两个 Vagrantfiles 中:

config.vm.provider "virtualbox" do |vb|
  vb.memory = 2048
 end

 config.vm.provision "shell", inline: <<-SHELL
   # obligatory provisioning goes here
 SHELL

有什么方法可以配置 vagrant,以便当我运行 vagrant init 时,这行代码已经存在于 Vagrantfile 中?

最佳答案

试试这个 https://www.vagrantup.com/docs/other/environmental-variables.html#vagrant_default_template

export VAGRANT_DEFAULT_TEMPLATE=~/.vagrant.d/Vagrantfile.erb 放入 ~/.bash_profile

touch ~/.vagrant.d/Vagrantfile.erb 

内容

Vagrant.configure("2") do |config|
  config.vm.define "main"
  config.vm.box = "<%= box_name %>"
  <% if box_version -%>
  config.vm.box_version = "<%= box_version %>"
  <% end -%>
  <% if box_url -%>
  config.vm.box_url = "<%= box_url %>"
  <% end -%>
  # config.vm.network "forwarded_port", guest: 80, host: 8080
  config.vm.network "private_network", type: "dhcp"
  config.vm.provider "virtualbox" do |vb|
    vb.memory = "4096"
    vb.cpus = 4
  end
end

然后source ~/.bash_profile

vagrant init ubuntu/bionic64

效果很好!

关于 Vagrant 默认配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42041419/

相关文章:

windows - 使用 vagrant Windows 10 没有输出

google-chrome - Vagrant Vhost domains (app.dev) 您现在无法访问,因为该网站使用 HSTS。在 Chrome 上

laravel - 无法使用 Vagrant 在浏览器中查看 Laravel 项目

ubuntu - 在 Vagrant 中提交更改

amazon-web-services - 让 Vagrant 与 AWS 配合使用

ubuntu - 带有 Gnome 的 Ubuntu 的 Vagrant base box

Vagrant 在销毁之前分离 .vdi 文件或者只是不删除它

hadoop - 使用Vagrant设置虚拟机,但通过VirtualBox UI启动

java - 在java中解析vagrant文​​件

virtualbox - Vagrant:销毁不工作