你可以用这样的ansible做到这一点:
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
或者带壳
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