I'm building my Windows server 2012 vm with packer and when I'm doing a vagrant up
it's failing because the folder name already exists…
Here is my json file for packer
{
"builders": [
{
"boot_wait": "2m",
"communicator": "winrm",
"disk_size": "{{user `disk_size`}}",
"floppy_files": [
"{{user `autounattend`}}",
"./scripts/disable-winrm.ps1",
"./scripts/enable-winrm.ps1"
],
"guest_additions_mode": "disable",
"guest_os_type": "Windows2012_64",
"headless": "{{user `headless`}}",
"iso_checksum": "{{user `iso_checksum`}}",
"iso_checksum_type": "{{user `iso_checksum_type`}}",
"iso_url": "{{user `iso_url`}}",
"shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
"type": "virtualbox-iso",
"vboxmanage": [
[
"modifyvm",
"{{.Name}}",
"--memory",
"2048"
],
[
"modifyvm",
"{{.Name}}",
"--nic1",
"NAT"
],
[
"modifyvm",
"{{.Name}}",
"--cpus",
"2"
]
],
"vm_name": "windows_2012_r2",
"winrm_password": "vagrant",
"winrm_timeout": "{{user `winrm_timeout`}}",
"winrm_username": "vagrant"
}
],
"post-processors": [
{
"keep_input_artifact": false,
"output": "vagrantenv/windows_2012_r2_{{.Provider}}.box",
"type": "vagrant",
"vagrantfile_template": "vagrantfile-windows_2012_r2.template"
}
],
"provisioners": [
{
"scripts": [
"./scripts/vm-guest-tools.bat",
"./scripts/enable-rdp.bat"
],
"type": "windows-shell"
}
],
"variables": {
"autounattend": "./answer_files/2012_r2/Autounattend.xml",
"disk_size": "61440",
"disk_type_id": "1",
"headless": "true",
"iso_checksum": "5b5e08c490ad16b59b1d9fab0def883a",
"iso_checksum_type": "md5",
"iso_url": "./iso/windows_2012_r2.iso",
"winrm_timeout": "30m"
}
}
And my post-processors
template
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version ">= 1.6.2"
Vagrant.configure("2") do |config|
config.vm.box = "windows_2012_r2"
config.vm.communicator = "winrm"
# Admin user name and password
config.winrm.username = "vagrant"
config.winrm.password = "vagrant"
config.vm.guest = :windows
config.windows.halt_timeout = 15
config.vm.network :forwarded_port, guest: 3389, host: 3389, id: "rdp", auto_correct: true
config.vm.provider :virtualbox do |v, override|
#v.gui = true
v.name = "windows_2012_r2"
v.customize ["modifyvm", :id, "--memory", 2048]
v.customize ["modifyvm", :id, "--cpus", 2]
v.customize ["modifyvm", :id, "--vram", 128]
v.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
v.customize ["setextradata", "global", "GUI/SuppressMessages", "all" ]
end
end
This steps works porperly and I end up with a file windows_2012_r2_virtualbox.box
Then I run vagrant init -f windows_2012_r2 windows_2012_r2_virtualbox.box
and finally vagrant up
following this I'm getting the error:
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'windows_2012_r2' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Box file was not detected as metadata. Adding it directly...
==> default: Adding box 'windows_2012_r2' (v0) for provider: virtualbox
default: Unpacking necessary files from: file:///D:/Dev/packer-windows/vagrantenv/windows_2012_r2_virtualbox.box
default:
==> default: Successfully added box 'windows_2012_r2' (v0) for 'virtualbox'!
==> default: Importing base box 'windows_2012_r2'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: windows_2012_r2
The name of your virtual machine couldn't be set because VirtualBox
is reporting another VM with that name already exists. Most of the
time, this is because of an error with VirtualBox not cleaning up
properly. To fix this, verify that no VMs with that name do exist
(by opening the VirtualBox GUI). If they don't, then look at the
folder in the error message from VirtualBox below and remove it
if there isn't any information you need in there.
VirtualBox error:
VBoxManage.exe: error: Could not rename the directory 'D:\VM\VirtualBox\windows_2012_r2_1556359923004_28925' to 'D:\VM\VirtualBox\windows_2012_r2' to save the settings file (VERR_ALREADY_EXISTS)
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component SessionMachine, interface IMachine, callee IUnknown
VBoxManage.exe: error: Context: "SaveSettings()" at line 3194 of file VBoxManageModifyVM.cpp
I notice that at the stage
Successfully added box 'windows_2012_r2' (v0) for 'virtualbox'!
vagrant creates the folder windows_2012_r2 in the virtualbox folder and then at this stagedefault: Importing base box 'windows_2012_r2'...
vagrant creates a folder windows_2012_r2_1556359923004_28925 and try to rename it to windows_2012_r2 but doesn't manage to it because it already exist.windows_2012_r2 folder has the windows_2012_r2-disk001_2.vmdk file
windows_2012_r2_1556359923004_28925 has windows_2012_r2_1556359923004_28925.vbox file
I'm confused how vagrant manage the Virtualbox name when importing a packer created box why vagrant is renaming the folder name, and not using the already existing target folder?