首页 > 解决方案 > 如何从 Vagrantfile 写入配置文件

问题描述

您好我正在尝试将目录索引指令添加到 Vagrantfile 中的 Apache 的默认 VirtualHost。我想知道是否有办法从 Vagrantfile 编辑文件(我使用的是内联 SHELL)。我知道我可以将整个 VH 文件复制到客户机,但我想知道如果可能的话如何写入文件。

谢谢!

标签: vagrantprovisioningvagrantfile

解决方案


You can do that with ansible like this:

config.vm.provision "ansible_local" do |ansible|
    ansible.verbose   = "vv"
    ansible.become    = true # execute as root
    ansible.playbook  = "relative_path_to_ansible_file/playbook.yml"
  end 

or with a shell

Vagrant.configure("2") do |config|
  config.vm.provision "shell" do |s|
    s.inline = "echo $1"
    s.args   = "'hello, world!'"
  end
end

https://www.vagrantup.com/docs/provisioning/shell.html


推荐阅读