Creating New Windows Server 2012 r2 Vagrant Box - vagrant

I'm trying to create a Windows Server 2012 R2 Vagrant box from a VirtualBox instance. Most of the tutorials I follow just say to run
vagrant package --base packer-virtualbox-iso-1450701695 --output windows-2012r2.box
and then run
vagrant box add windows-2012r2 windows-2012r2.box
but this results in
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'windows-2012r2' (v0) for provider:
box: Unpacking necessary files from: file://E:/VirtualBox%20VMs/windows-2012r2.box
box: Progress: 100% (Rate: 62.0M/s, Estimated time remaining: --:--:--)
The "metadata.json" file for the box 'windows-2012r2' was not found.
Boxes require this file in order for Vagrant to determine the
provider it was made for. If you made the box, please add a
"metadata.json" file to it. If someone else made the box, please
notify the box creator that the box is corrupt. Documentation for
box file format can be found at the URL below:
Any suggestions? Also I'm trying to do this because I need to run a Powershell command on the box before saving it, so a pointer to how I'd be able to update and save an existing vagrant box so that it can be reused would be good too.

Related

vagrant debian/buster64 box failed (win10)

i try to setup vagrant 'debian/buster64' manually on win10 but got failure... my steps:
download box file from https://vagrantcloud.com/debian/boxes/buster64/versions/10.4.0/providers/virtualbox.box
try to setup...
$ vagrant box add --name 'debian/buster64' '4d7865da-6242-4853-bc6c-807a63c734e6'
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'debian/buster64' (v0) for provider:
box: Unpacking necessary files from: file://D:/Downloads/4d7865da-6242-4853-bc6c-807a63c734e6
box:
The box failed to unpackage properly. Please verify that the box
file you're trying to add is not corrupted and that enough disk space
is available and then try again.
The output from attempting to unpackage (if any):
x ./metadata.json: Cannot extract through symlink \\\\?\\C:\\Users\\mat\\.vagrant.d
x ./box.ovf: Cannot extract through symlink \\\\?\\C:\\Users\\mat\\.vagrant.d
x ./buster.vmdk: Cannot extract through symlink \\\\?\\C:\\Users\\mat\\.vagrant.d
x ./Vagrantfile: Cannot extract through symlink \\\\?\\C:\\Users\\mat\\.vagrant.d
bsdtar.EXE: Error exit delayed from previous errors.
os: windows 10
version: 1909
build: 18363.900
vagrant 2.2.9
Who knows what is wrong?
I assume you have created a Windows Junction to redirect your user profile to another drive (as did I). Well, Vagrant does not like that at all.
Luckily, you can explicitly set the base config directory (.vagrant.d) for your Vagrant installation via the environment variable VAGRANT_HOME. Assuming you moved your profile to drive D, you should set the environment variable as follows:
VAGRANT_HOME=D:\Users\mat\.vagrant.d

Vagrant up on Windows 7: error setting certificate verify locations

I've just met Vagrant, trying to pass Getting Started instructions https://www.vagrantup.com/intro/getting-started/index.html
Before diving into your first project, please install the latest version of Vagrant. And because we will be using VirtualBox as our provider for the getting started guide, please install that as well.
My host machine is Windows 7 x64. Virtualbox is 5.1.14r112924. Virtualization is enabled: I successfully use Windows XP virtual machine.
So I installed the latest Vagrant version 2.0.0. And I updated Powershell from 2.0 to 5.0 to fix vagrant up does nothing issue.
So, the instructions from Getting started:
vagrant init hashicorp/precise64: okay, file Vagrantfile appeared;
vagrant up, getting started says:
After running the above two commands, you will have a fully running virtual machine in VirtualBox running Ubuntu 12.04 LTS 64-bit.
but I see:
E:\VM\v_demo>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'hashicorp/precise64' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
The box 'hashicorp/precise64' could not be found or
could not be accessed in the remote catalog. If this is a private
box on HashiCorp's Vagrant Cloud, please verify you're logged in via
`vagrant login`. Also, please double-check the name. The expanded
URL and error message are shown below:
URL: ["https://vagrantcloud.com/hashicorp/precise64"]
Error: error setting certificate verify locations:
CAfile: /mingw64/ssl/certs/ca-bundle.crt
CApath: none
and in my working folder following file tree:
| Vagrantfile
|
\---.vagrant
\---machines
\---default
\---virtualbox
vagrant_cwd
Internet search of this error shows results about curl и git but they are not used here.
Recommendations about trying vagrant login from the error message are also not clear. As said at https://www.vagrantup.com/docs/cli/login.html
Command: vagrant login
The login command is used to authenticate with the HashiCorp's Vagrant
Cloud server. Logging is only necessary if you are accessing protected
boxes or using Vagrant Share.
Logging in is not a requirement to use Vagrant. The vast majority of
Vagrant does not require a login. Only certain features such as
protected boxes or Vagrant Share require a login.
I don't think that test example is private.
And I cannot find Create account button anywhere.
What am I missing?
UPD
Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.vm.box_download_insecure = true
end
Value config.vm.box_download_insecure = true didn't helped: same result.
UPD2
I've found how to create account https://app.vagrantup.com/account/new (before I used mobile version).
vagrant login didn't helped: same results
Actual problem was proxy server.
Setting Windows environment variable https_proxy=http://192.168.x.xxx:3128 solved the problem.
Manual solution:
Manually download the .box-file from https://hashicorp-files.hashicorp.com/precise64.box to local folder local_box\precise64.box;
Add path to local .box-file inside Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "local_box/precise64.box"
end
vagrant up now works as expected.

Is it possible to enable WinRM in a Modern.ie VM or Vagrant Box by repackaging it with Packer?

There are these free like free beer virtual machines (VM) from Microsoft which one can download from modern.ie and use for testing or whatever. And there is this nice Gist on Github which explains how to enable WinRM support on that VMs. Unfortunately this requires manual interaction with the VM after initial boot up (step 2. in Gist). Is it possible to let Packer do this job using it´s builder type virtualbox-ovf (VIRTUALBOX BUILDER (FROM AN OVF/OVA))? If it is possible can you provide some example code, please.
Or asked another way: How to create a Vagrant Box from an existing VirtualBox image (.ova file) or from an existing Vagrant Box (.ovffile) with Packer?
What you asked is described in Step 4
Package
Since there's a lot of Windows specific configuration, you can include
the Vagrantfile in the package command so winrm and virtualbox
configuration get's default values when the repackaged is used for
other purposes. Remember to run the command in the same directory the
Vagrantfile resides:
$ vagrant package --output "yourboxname" --Vagrantfile Vagrantfile
After that you're all set!
once you complete step2 and 3, you will run step4 which recreate a vagrant box from the updated VM and you can re-use this box
Or asked another way: How to create a Vagrant Box from an existing VirtualBox image (.ova file) or from an existing Vagrant Box (.ovffile) with Packer?
This is not possible, shortly speaking, packer creates Vagrant box from OS ISO distribution, not from existing VM
You can connect to Windows modern.ie VM with ssh (Openssh service runs at startup). You'll have a very limited shell, but enough to call cmd.exe or powershell, and activate WinRM. On Windows 10 VM, you just have to change the network type to something not public. That's it.

artifactory vagrant repo, getting json or 404 response when trying to download the image

Good time of the day all, I have setup a pro version of artifactory and I have setup a vagrant repo with 1 file. however, when i try to get the file from artifactory i get the following response instead of downloading the file and this is due to setting incorrect repo layout. by default artifactory sets a simple-default layout that I think is causing the issue
{"name":"vagrant-centos-base.box","description":null,"short_description":null,"versions":[]}
Obviously, when i try to use vagrant up command with the url to the repo/file specified i get the following error:
bsdtar.EXE: Error opening archive: Unrecognized archive format
which i strongly suspect is due to the vagrant downloading that response instead of the actual file.
What am I missing?
Thank You in advance!
here is the output from vagrant:
Bringing machine 'webserver' up with 'virtualbox' provider...
Bringing machine 'webserver1' up with 'virtualbox' provider...
Bringing machine 'appserver' up with 'virtualbox' provider...
==> webserver: Box 'vagrant-centos-base' could not be found. Attempting to find
and install...
webserver: Box Provider: virtualbox
webserver: Box Version: >= 0
==> webserver: Loading metadata for box 'https://{url}/artifa
ctory/api/vagrant/B6_Vagrant/vagrant-centos-base'
webserver: URL: https://{url}/artifactory/api/vagrant/B6_
Vagrant/vagrant-centos-base
==> webserver: Adding box 'vagrant-centos-base' (v1.0.0) for provider: virtualbo
x
webserver: Downloading: https://{url}/B6_Vagrant/vagrant-
centos-base.box
webserver: Progress: 0% (Rate: 0curl:/s, Estimated time remaining: --:--:--)
webserver:
An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.
The requested URL returned error: 404 Not Found
as you can see, now its getting the medatada, but its failing to download the file since the artifactory is giving 404. same as when i try to do it manually
It seems that you uploaded the vagrant box to Artifactory without provide the box metadata - name, provider, version.
When vagrant is trying to download the box via the vagrant API, it expects a JSON response which describes the image and provided a download link, for example:
{"name":"debian-current","description":null,"short_description":null,"versions":[{"version":"12","status":"active","description_html":null,"description_markdown":null,"providers":[{"name":"Provider","url":"http://localhost:8081/artifactory/local-vagrant/debian-current.box"}]}]}
If this metadata is missing, vagrant does not know how to proceed.
You can still install a box uploaded without metadata. You will have to use a direct download URL for the box (not passing via the Vagrant API), for example:
vagrant box add http://myserver/B6_Vagrant/vagrant-centos-base.box --name vagrant-centos-base.box
This will return the actual bits of the box. Notice that you will have to provide the vagrant add command with the name of the images using the --name parameter.
Uploading the box with the metadata can be done using the deployment UI or the REST API.
You can use the "Set Me Up" feature for getting detailed instructions which will help with the process
For more info please take a look at the Vagrant Repositories section in the Artifactory documentation
It turned out i had to add the /artifactory to the artifactory URL in the settings. This way url in the metadata started to point to the correct location and and its all working now

A VirtualBox machine with the name 'homestead' already exists

Since homestead 2.0 homestead laravel has not been working
I don't know why 'homestead init' creates a Homestead.yaml file in mydirectory/.homestead
and not in the project directory. Homestead up OR Vagrant up create the following message
A VirtualBox machine with the name 'homestead' already exists.
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'laravel/homestead'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'laravel/homestead' is up to date...
A VirtualBox machine with the name 'homestead' already exists.
Please use another name or delete the machine with the existing
name, and try again.
I solved by using vboxmanage to get the ID of the VM.
$ vboxmanage list vms
"my-vm" {c700b8b6-b766-4638-871b-736b44b7db18}
Copy the ID of the desired VM (the c700…db18 string) into the contents of ~/.vagrant/machines/default/virtualbox/id. Save the file then run vagrant up to get the vm working without having to destroy it.
For me, the machine was not showing up as an active VM in the VirtualBox application. To fix I had to do this:
vagrant global-status
This gave me the ID of the machine that I needed to destroy. With the ID, run:
vagrant destroy {VM ID}
I had to run that in sudo to actually destroy the machine. At that point, I was able to run
vagrant up
From the following message :
A VirtualBox machine with the name 'vm_name' already exists.
Please use another name or delete the machine with the existing
name, and try again.
I listed current running virtual machines from the command line :
VBoxManage list vms
Result :
"vm_name" {8ba467b7-da96-4f68-9bf8-671dd6f0d007}
Then proceeded with the removal of the offending virtual machine :
VBoxManage unregistervm 8ba467b7-da96-4f68-9bf8-671dd6f0d007 --delete
You probably have a virtualbox running! Open the programme virtualbox and shut down the other virtualbox ;)
http://smallbusiness.chron.com/shut-down-virtualbox-43657.html
If this isn't working then you might want to delete the old homestead folder and place all your projects in the new folder ;)
I'm a bit late to the party on this, but for anyone else having this issue SergioPeluzzi came closest, but didn't get the cigar with this:
Seek for vb.name = settings["name"] = "homestead" line and changed "homestead" to "HOMESTEAD" and "vói lá"
The line is actually:
vb.name = settings["name"] ||= "homestead"
As you can see from the bit that says settings["name"], you just need to add a name field to your Homestead YAML file, e.g.
memory: 2048
cpus: 1
provider: virtualbox
name: my-sexy-homestead-box
I edited Homestead.yaml and add new name for it
ip: "192.168.10.10"
memory: 2048
cpus: 4
provider: virtualbox
name: my-new-homestead-box-name
I solved this editing /Homestead_folder/scripts/homestead.rb
Seek for vb.name = settings["name"] = "homestead" line and changed homestead to HOMESTEAD and "vói lá" that worked for me.
I had an old .vagrant directory in my project which was causing the error :)
If this doesn't fix it for you i would suggest opening VirtualBox and removing all VirtualBoxes and trying again.
You just have to add the key name to your homestead.yaml file right after the provider like this:
name: name_of_you_machine
That works for me.
I had same issue today. Spend few hours to find the solution.
If by any reason you can't find the list of exiting virtual machines then type in terminal
sudo virtualbox
This will run Virtual Box in GUI. You should see the the full list of VMs and from there you'd be able to manage them.
Typing "virtualbox" only won't show anything. You need to be root (administrator).
Thanks to mightyspaj for the tip.
Commands to execute:
vagrant box list
vagrant box remove laravel/homestead
vagrant global-status
vagrant destroy nameOfYourBox
Open your VirtualBox and delete all itens of your homestead
vagrant up
I opened the virtualBox and then deleted homestead vm that was created earlier. It helped.
I was receiving the same error message, even after running "homestead destory", and "vagrant destroy". Same as you, I was using the VirtualBox provider, vagrant, and homestead. Here's what I did:
Opened VirtualBox GUI. I see "homestead" as a VM, but I cannot remove it, button is greyed out.
I logged out of my OS, logged back in and re-opened VirtualBox. Status is now "aborted" and i'm able to remove.
There were some residual files in ~/VirtualBox\ VMs/homestead, so i ran rm -r /Users/gabriel/VirtualBox\ VMs/homestead
I am now able to run "homestead up"
Open VirtualBox GUI. See for your VM and remove it.
It solved my problem.
Sometimes you might not want to delete old box. Yesterday may old Vagrant has broken, I've updated Vagrant and Virtualbox but folders mapping didn't work. I wanted to run new box and had this error.
I didn't want to remove old box (because I wanted to run some backups) but I wanted to run new box. The solution was running VirtualBox, right click on Homestead machine and choose Settings and then changing name from homestead to homestead_old.
After that I was able to install homestead but had this old machine and could also run this to make any backups I needed.
If you are a Windows User, make sure you delete C:\Users\<Username>\VirtualBox VMs\homesteadfolder. Because if there is still a folder named homestead, the action of vagrant up will not be completed
If you want to keep keep your machine, without destroying and recreating following steps should solve your problem.
(I work on OS X El Captain, Vagrant 1.8.1)
Run homestead in debug mode
homestead --debug up
Look for something like in the output:
INFO machine: Initializing machine: default INFO machine: -
Provider: VagrantPlugins::ProviderVirtualBox::Provider INFO machine:
- Box: # INFO machine: - Data dir: /Users/YOUR_HOME_DIR/Workspace/Homestead/.vagrant/machines/default/virtualbox
Data dir, is the path which is interesting for you.
Then vboxmanage list vms
"homestead" {0e8438b9-4a67-4fb1-80cb-2c62cf04ab5c}
"settler_default_1447385930122_73498_1474294682778_13108"
{93ecb93f-f159-4406-a384-5312b4d3ab34}
Edit id file, in the path which you found out in the previous command
vi /Users/YOUR_HOME_DIR/Workspace/Homestead/.vagrant/machines/default/virtualbox/id
Replace content of that file, with the id of the VM you want to fix, in this scenario it is
0e8438b9-4a67-4fb1-80cb-2c62cf04ab5c
Now try
homestead up
VM should start booting. It might work, or you might have issues with ssh authentication
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying...
To fix that do following
Check Homestead SSH config
homestead ssh-config
You should get something like
Host default HostName 127.0.0.1 User vagrant Port 2222
UserKnownHostsFile /dev/null StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile
"/Users/pryznar/.vagrant.d/insecure_private_key"
IdentitiesOnly yes
LogLevel FATAL
Edit IdentityFile file
/Users/YOUR_HOME_DIR/.vagrant.d/insecure_private_key
Check Homestead.yml
cat /Users/YOUR_HOME_DIR/.homestead/Homestead.yaml
Then copy path to the file under the key keys, and copy private key from that file
cat ~/.homestead/ssh/id_rsa
Last step is to replace private key in /Users/YOUR_HOME_DIR/.vagrant.d/insecure_private_key with the one you just copied
Now try rung homestead again, should work.
homestead up
I got some warnings, but so far it works without issues
==> default: Warning: Using a password on the command line interface can be insecure.
==> default: ERROR 1045 (28000): Access denied for user 'homestead'#'localhost' (using password: YES) The SSH command
responded with a non-zero exit status. Vagrant assumes that this means
the command failed. The output for this command should be in the log
above. Please read the output to determine what went wrong.
You can open the VirtualBox GUI and remove the conflicting virtual machine.
None of this worked for me. I was using an old dev machine
I attempted:
vagrant global-status > destroy any by id which you don't need or match what is conflicting
open virtualbox and remove + delete files for any which you don't need or are conflicting
What worked:
locate your ~/.vagrant/machines/ or ~/.vagrant.d/boxes folder. In my case, it contained the conflicting vm and also a bunch of old left over vm machines which steps 1 & 2 did not remove for some reason.
after clearing these, everything worked fine again, finally!
Windows10
Edit Homestead.yaml file and give a new name for the box:
ip: "192.168.10.10"
memory: 2048
cpus: 2
provider: virtualbox
name: my-new-vbox #new name for the box
and run vagrant up or vagrant up --provision
Or
Open Virtualbx application in GUI and delete all the virtualbox that was causing problem and run the above command
Or
Delete the "Vagrant" file inside homestead folder and run the above command.
I had the following error:
Error:
A VirtualBox machine with the name 'homestead-7' already exists.
Please use another name or delete the machine with the existing
name, and try again.
Solution:
Find the VirtualBox VMS folder, in my case it was in ~/VirtualBox VMs
List the elements in the folder with ls command, and review if the virtual machine is there
Delete the folder with the name of the machine, in my case homestead-7
Re-execute the vagrant up command in the homestead folder
That's all, I hope it's helpful, that was my solution.
Regards!
In my case the following article provide the solution. There was a folder named homestead inside the path /var/root/VirtualBox VMs/ that was causing the issue. Once this folder was removed, rm -r homestead, the issue was resolved. If you can not see or have access to this path execute the following commands in your terminal windows:
$ sudo -s
$ cd /var/root/VirtualBox\ VMs
And proceed to delete the homestead folder.
Add --force after box, and before your given name.
Renaming an already existing default VM
Disclaimer
The following procedure will destroy your VM and may be only suiteable in a desting-environment like mine! For production environments, consider to repair the association like described here
I had this problem after overriding the default name of an already existing VM by using
Vagrant.configure("2") do |config|
config.vm.define :ubuntu_test
where the VirtualBox name was also set (as a newbie I assumed that Vagrand will use this name too)
config.vm.provider "virtualbox" do |vb|
vb.name = "Ubuntu-Test"
end
By adding config.vm.define it seems that Vagrant doesn't associate the VirtualBox VM any more with the Vagrant file since even vagrant destroy -f say VM not created but vagrant up throw this error
A VirtualBox machine with the name 'Ubuntu-Test' already exists.
To delete those zombie VM
If the VM is running, stop it first: vboxmanage shutdown <VMName> (Here the name is Ubuntu-Test)
Get the Id by running vboxmanage list vms
Delete it: vboxmanage unregistervm <Id> --delete
Now your VM can be re-created using vagrant up
Using vagrant global-status --prune, your new name is present
For me id file was present in the below-mentioned location.
D:\drupalvm.vagrant\machines\drupalvm\virtualbox
After a few hours of troubleshooting, nothing else worked for me, as no one mentioned this little detail.
Depending on your privileges at the time of installation, you may need to run virtualbox as an administrator. It was only when I did this that I saw my vagrant boxes in the list of virtual machines.
I then proceeded to remove my virtual machine named homestead from virtualbox, and the problem was solved.
If you're using homestead in Windows, just open up your Oracle VM VirtualBox and delete the homestead VM.
The Vagrant relies on VirtualBox (if that's the default provider) so it checks for existing environment first before provisioning your VM.
It is executing the following command:
VBoxManage list vms
and when it finds the VM with the same hostname, so it'll fail.
You can debug it by:
vagrant --debug up
to find out the exact reason.
Solution
If you're planning to use multiple VMs in different folders, then you need to change your config.vm.hostname (possibly config.vm.provider(name) as well) in your Vagrantfile to make it unique. Or simply remove it, so Vagrant will assign a different name for each VM.
If that's not the case, simply shutdown and unregister previous VM which conflicts by running:
VBoxManage controlvm NAMEOFVM poweroff
VBoxManage unregistervm NAMEOFVM --delete
and re-run your vagrant up.
If it fails on directory rename (because you missed --delete), then rename or remove the destination folder, for example:
rm -fr ~/"VirtualBox VMs/NAMEOFVM"
and re-try again.
This problem may be related to: GitHub issue #2969 - vagrant up not detecting a previously run VM
In my case, nothing was indicating that the VM "already exists" besides that error message. Nothing on VirtualBox UI, nothing returned by “vboxmanage list vms”, nothing through “vagrant global-status”, it didn’t exist in “.vagrant.d\boxes” and so on. I resolved it by manually creating a new same-name VM in the VM VirtualBox Manager (using the “new” button + accepting all the defaults), and then removing it (right-click > remove). After that, the “vagrant up” worked as expected.
I had the same issue today. Windows 10. I recently had updated Homestead, so the error was probably because of that. I tried it all, destroy, up, delete folders, whatever. Whenever I tried to run vagrant up, it was showing this kind of errors. The solution? After updating, I noticed that Homestead is now naming the boxes by the project folder name, and Homestead.yaml has all that infos. I just run that Homestead Windows configuration vendor\\bin\\homestead make and later them a vagrant up (before making sure it was all clean) and voilá, looks like the machine is booting now. =) Try that if you need it.

Resources