【发布时间】:2020-10-07 11:17:23
【问题描述】:
我正在尝试在 vagrant up 特权和提升权限期间执行 powershell 脚本。我在 Windows 机器上使用 Vagrant 2.2.10。该脚本与 Vagrantfile 位于同一目录中。我设法获得了正确的触发器,但无法使用 trigger.run 正确执行我的 powershell 脚本。
这是我的 Vagrantfile 的相关部分:
ENV['VAGRANT_EXPERIMENTAL'] = "typed_triggers"
Vagrant.configure("2") do |config|
override.trigger.before :'VagrantPlugins::HyperV::Action::StartInstance', type: :action do |trigger|
trigger.ruby do |env, machine|
machine.ui.info("------------------ Configure Node with Powershell Script -------------------")
trigger.run = {
#privileged: "true"
#powershell_elevated_interactive: "true"
inline: <<-SHELL
echo hhhhhhh > 123.log
Write-Host "test"
SHELL
}
trigger.run = { path: './test.ps1'}
trigger.run = { inline: "./test.ps1 -a 'test1' -b 'test2" }
trigger.run = { privileged: "true", powershell_elevated_interactive: "true", path: "powershell test.ps1", args: ["-a test1", "-b test2 "] }
#trigger.run = { privileged: "true", powershell_elevated_interactive: "true", :path => "test.ps1", :args => "testarg1, testarg2"}
machine.ui.info("------------------ Configuration of Node finished -------------------")
end
end
end
在 vagrant.log 中我找不到任何可以提供帮助的具体错误:
INFO trigger: Firing trigger for action VagrantPlugins::HyperV::Action::StartInstance on guest server1
INFO interface: info: Running action triggers before VagrantPlugins::HyperV::Action::StartInstance ...
INFO interface: info: ==> server1: Running action triggers before VagrantPlugins::HyperV::Action::StartInstance ...
==> server1: Running action triggers before VagrantPlugins::HyperV::Action::StartInstance ...
DEBUG trigger: Running trigger 69600289-3cee-4dde-a9fa-2ac9bec33409...
INFO interface: info: Running trigger...
INFO interface: info: ==> server1: Running trigger...
==> server1: Running trigger...
INFO interface: info: ------------------ Configure Node with Powershell Script -------------------
INFO interface: info: ==> server1: ------------------ Configure Node with Powershell Script -------------------
==> server1: ------------------ Configure Node with Powershell Script -------------------
DEBUG provisioner: Provisioner defined:
INFO interface: info: ------------------ Configuration of Node finished -------------------
INFO interface: info: ==> server1: ------------------ Configuration of Node finished -------------------
==> server1: ------------------ Configuration of Node finished -------------------
上述 trigger.runs 均无效。希望你们中的任何人都知道如何解决这个问题!
我怎样才能得到这份工作?
谢谢..
【问题讨论】:
-
为什么要为此使用触发器而不是配置器?
-
来宾机器上没有使用provisoner吗?我想在主机上的 vagrantfile 的同一目录中执行一个脚本。或者配置器可以在本地使用吗?
标签: powershell vagrant hyper-v