框中打包的Vagrantfile(通过打包程序)未使用

时间:2015-10-20 06:42:54

标签: vagrant vagrantfile packer

我使用为我正在运行的研讨会创建了一个框,并通过Vagrant后处理器中的vagrantfile_template指令将打包在框中如图所示:

...
"post-processors": [{
  "type": "vagrant",
  "vagrantfile_template": "vagrantfile_templates/workshop",
  "compression_level": "{{user `compression_level`}}",
  "output": "fedora-22-x86_64.box"
}],
...

结果.box的内容是:

% tar -tf workshop.box
Vagrantfile
box.ovf
metadata.json
packer-fedora-22-x86_64-disk1.vmdk

框中Vagrantfile的内容似乎正常,并包含打包程序配置中指定的vagrantfile_template的内容。请注意,此Vagrantfile定义了两个名为clientserver的虚拟机:

% tar -O -xf freeipa-workshop.box Vagrantfile

# The contents below were provided by the Packer Vagrant post-processor

Vagrant.configure("2") do |config|
  config.vm.base_mac = "0800278AF3E8"
end


# The contents below (if any) are custom contents provided by the
# Packer template during image build.
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|

  config.vm.box = "workshop"
  config.vm.synced_folder ".", "/vagrant", disabled: true

  config.vm.define "server" do |server|
    server.vm.network "private_network", ip: "192.168.33.10"
    server.vm.hostname = "server.ipademo.local"
  end

  config.vm.define "client" do |client|
    client.vm.network "private_network", ip: "192.168.33.20"
    client.vm.hostname = "client.ipademo.local"
  end

end

我将这个方框添加到名为workshop

的流浪汉
% vagrant box add --name workshop workshop.box 
==> box: Adding box 'workshop' (v0) for provider: 
    box: Downloading: file:///.../workshop.box
==> box: Successfully added box 'workshop' (v0) for 'virtualbox'!
% vagrant box list
workshop                  (virtualbox, 0)

问题描述

当我执行vagrant init workshop然后vagrant up时,框中包含的Vagrantfile不会被应用:

% vagrant init workshop
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
% cat Vagrantfile 
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "workshop"

  ... and so on (the rest of the default Vagrantfile)

% vagrant up --provider virtualbox
Bringing machine 'default' up with 'virtualbox' provider...
...

哇!为什么会提起defaultAccording to the Vagrantfile docs应该使用随盒子打包的Vagrantfile,并且当前目录中包含的其他Vagrantfile应该合并到其中。但事实似乎并非如此。

Vagrant 1.7.2 是正在使用的版本。

我希望研讨会参与者能够调出框中包含的Vagrantfile中定义的VM,而不在带外提供Vagrantfile(以便最小化依赖性)。我错过了重要的事情吗?

1 个答案:

答案 0 :(得分:0)

正如我们所知,Vagrant以预先确定的顺序加载和合并多个Vagrantfiles here(在同一部分中,他们也指出多个Vagrant.configure块也可以)。< / p>

当Vagrant无法使用config.vm.communicator = "winrm"获取捆绑在.box中的vagrantfile_template配置时,我遇到了同样的问题。

但是,通过使用vagrant --debug,我注意到Vagrant似乎已经从同一个框的先前版本中缓存了捆绑的Vagrantfile:

INFO loader: Set :"26224240_win7sp1_x64_virtualbox" = ["#<Pathname:/home/thomas/.vagrant.d/boxes/win7sp1_x64/0/virtualbox/Vagrantfile>"]

有人会认为vagrant destroy会删除vagrant.d中的关联文件,但事实并非如此,因此我可以通过手动删除~/.vagrant.d/boxes/win7sp1_x64来解决问题。

我确认它现在正在按预期工作,因为我们确实使用了WinRM:

==> default: Waiting for machine to boot. This may take a few minutes...
    default: WinRM address: 127.0.0.1:55985
    default: WinRM username: vagrant
    default: WinRM execution_time_limit: PT2H
    default: WinRM transport: negotiate
==> default: Machine booted and ready!

即使初始化目录中的Vagrantfile没有该配置:

Vagrant.configure("2") do |config|
    config.vm.box = "win7sp1_x64"
    config.vm.box_url = "/media/data/VagrantBaseBoxes/win7sp1_x64/win7sp1_x64-virtualbox.box"
end

<强> TL; DR:

确保没有&#34; old&#34; vagrant.d中存在可能会覆盖&#39; packer - ed框中配置内容的Vagrantfiles(请参阅&#34;加载顺序和合并&#34;在上面的链接中)

相关问题