首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Vagrant shell/路径置备程序置备Windows来宾?

如何使用Vagrant shell/路径置备程序置备Windows来宾?
EN

Stack Overflow用户
提问于 2015-03-24 01:49:24
回答 1查看 6.9K关注 0票数 6

我正在尝试使用Powershell来配置Windows Vagrant计算机。如果我以管理员身份启动Powershell,我已经验证了我的脚本可以在本地机器上运行。在Vagrant配给过程中,vagrant用户无法提升和运行脚本。

我知道Vagrant支持powershell脚本,那么使用它们进行配置需要做些什么呢?我最初的想法是尝试使用脚本启动一个新的Administrator Powershell,但我觉得一定有更好的方法。

我正在尝试使用System.Net.WebClientmsiexec下载一个文件进行安装。

Vagrantfile:

代码语言:javascript
复制
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
PROVISION_WIN7_SCRIPT = "provision_win7.ps1"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.define "win7", primary: false do |win7|
  config.vm.provision "shell", :path => "#{PROVISION_WIN7_SCRIPT}"
  config.vm.box      = "win7"
  config.vm.hostname = "win7"
  config.vm.communicator = "winrm"
  config.vm.network :private_network, ip: "10.10.10.10"
  config.vm.box_url = "https://atlas.hashicorp.com/designerror/boxes/windows-7/versions/1.0/providers/virtualbox.box"   
    config.vm.provider :virtualbox do |vb|
      vb.gui = true
      vb.customize ["modifyvm", :id, "--memory", 1024]
      vb.customize ["modifyvm", :id, "--cpus", 1]
      vb.customize ["modifyvm", :id, "--vram", "32"]
      vb.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
      vb.customize ["setextradata", "global", "GUI/SuppressMessages", "all" ]
  end
  end
end

编辑:

我今天再次尝试使用我当时运行的: Vagrant 1.6.3,Virtualbox 4.3.30。当我打开我的流浪者框时,我没有看到任何错误输出:

代码语言:javascript
复制
Bringing machine 'win7' up with 'virtualbox' provider...
==> win7: Importing base box 'designerror/windows-7'...
==> win7: Matching MAC address for NAT networking...
==> win7: Checking if box 'designerror/windows-7' is up to date...
==> win7: Setting the name of the VM: vagrant_win7_1453859492744_23074
==> win7: Clearing any previously set network interfaces...
==> win7: Preparing network interfaces based on configuration...
    win7: Adapter 1: nat
    win7: Adapter 2: hostonly
==> win7: Forwarding ports...
    win7: 3389 => 3389 (adapter 1)
    win7: 22 => 2222 (adapter 1)
    win7: 5985 => 55985 (adapter 1)
==> win7: Running 'pre-boot' VM customizations...
==> win7: Booting VM...
==> win7: Waiting for machine to boot. This may take a few minutes...
==> win7: Machine booted and ready!
==> win7: Checking for guest additions in VM...
==> win7: Setting hostname...
==> win7: Configuring and enabling network interfaces...
==> win7: Mounting shared folders...
    win7: /vagrant => /Users/dstark/Projects/itbestprac-pres/vagrant
==> win7: Running provisioner: shell...
    win7: Running: c:\tmp\vagrant-shell.ps1

在我的vagrant机器上,c:\tmp下有一个vagrant-shell.ps1vagrant-elevated-shell.ps1,如果我以vagrant用户的身份手动执行vagrant生成的提升的shell ps脚本,它就会安装。所以,我认为我的脚本是正确的。

如果我添加了config.winrm.usernameconfig.winrm.password,我仍然无法提升运行脚本所需的权限。在事件查看器中也没有任何信息。

EN

回答 1

Stack Overflow用户

发布于 2016-06-26 01:52:08

您可能需要将privileged标志添加到配置行:

代码语言:javascript
复制
config.vm.provision "shell", path: "scripts/provision.ps1", privileged: true

或者在你的例子中:

代码语言:javascript
复制
config.vm.provision "shell", :path => "#{PROVISION_WIN7_SCRIPT}", privileged: true
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29216975

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档