我有一个Vagrantfile
,其设置脚本如下所示。我用vagrant up
运行了几次,我知道前几个命令有效,但后来我知道这些命令没有成功。
Vagrantfile:
# -*- mode: ruby -*-
VAGRANTFILE_API_VERSION = "2"
$setup = <<END
# some bash code
# ...
# something that somehow never runs
sudo chown -R vagrant:vagrant /some/path
END
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "puppetlabs/centos-7.0-64-nocm"
config.vm.define "client", primary: true do |client|
client.vm.hostname = "client.example.com"
client.vm.network :private_network, ip: "192.168.250.10"
client.vm.provision "shell", inline: $setup
end
end
有什么方法可以查看在vagrant up
上运行脚本时会发生什么错误?
我尝试了vagrant up --debug &> vagrant.log
,但输出实际上是数千行,我找不到任何有用的东西(或者不知道要寻找什么,这更有可能)。
答案 0 :(得分:2)
echo
应该执行这个技巧并显示shell文件中的消息。
echo "running update ..."
sudo apt-get update
echo "running install lib ..."
sudo apt-get install --yes git-all libreadline-dev build-essential curl git m4 python-setuptools ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev
echo "install rvm ..."
curl -L https://get.rvm.io | bash -s stable --ruby=2.0.0
运行shell配置时,所有回显消息都将显示在输出中
如果您需要将stderr重定向到stdout,您可以执行grep * 2>&1
之类的操作 -
参考:http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html
答案 1 :(得分:1)
虽然FrédéricHenri的答案肯定是推荐和有用的,但vagrant还附带了一些内置的调试帮助,你可以read more about here,但基本上你可以vagrant up
带有调试标志以获取更多信息:
vagrant up --debug