cn_47
cn_47

Reputation: 15

Vagrant says 'not created'. How do I add a new box file?

I'm creating a virtual development environment with vagrant on my Windows 10. I've already installed box which has name 'dev1'(it is CentOS7.0).

I want to add a new box(CentOS6.7) named 'dev2'.

So I tried to add a box by command below

$ vagrant box add dev2 [box path]

after that, successfully added.

$ vagrant box list
dev1             (virtualbox, 2.3.1)
dev2             (virtualbox, 0)

Then I does $ vagrant init' and editing vagrantfile as below

Vagrant.configure("2") do |config|

    config.vm.define "dev1" do |dev1|
      dev1.vm.hostname = "dev1"
      dev1.vm.box = "bento/centos-7.2"
      dev1.vm.network "private_network", ip: "192.168.33.11"
    end

    config.vm.define "dev2" do |dev2|
      dev2.vm.hostname = "dev2"
      dev2.vm.box = "bento/centos-6.7"
      dev2.vm.network "private_network", ip:"172.16.1.2"
    end
end

Finishing edit, I entered command $ vagrant status but it says:

Current machine states:
dev1                      poweroff (virtualbox)
dev2                      not created (virtualbox)

Booting virtualbox manager, it shows no infomation of 'dev2'.

When I attemp to $ vagrant up dev2, it starts download CentOS6.7 box file instead of booting 'dev2' which I added earlier...

How do I add a new box besides existing environment?

Thank you in advance.

Upvotes: 0

Views: 2414

Answers (2)

dejavuguides
dejavuguides

Reputation: 43

I received the same message too, after trying the vagrant package --base command per Vagrant's guide.

$ vagrant package --base my-virtual-machine
`VM not created. Moving on...`

Specifically to get it working you must check and use the exact name that you may have preset via Vagrantfile and config.vm.name = "name you choose". You will also see this displayed in the VirtualBox (unless you changed it).

Here is an example screenshot of the default name that came out from my testing.

Use Virtual Box name

I'm using Powershell, so this was my outputs:

PS C:\Users\USER\OneDrive\Documents\Projects\Vagrant2> vagrant package --base Vagrant2_default_1598799939605_1106
==> Vagrant2_default_1598799939605_1106: Exporting VM...
==> Vagrant2_default_1598799939605_1106: Compressing package to: C:/Users/USER/OneDrive/Documents/Projects/Vagrant2/package.box

Upvotes: 0

Frederic Henri
Frederic Henri

Reputation: 53793

You have a mismatch in the box you have added in your vagrant configuration and the name you use in your Vagrantfile.

If you have added the box and gave them name with the output

$ vagrant box list
dev1             (virtualbox, 2.3.1)
dev2             (virtualbox, 0)

This names must match the value for config.vm.box from your Vagrantfile, so you need to use those dev1 and dev2 name in your Vagrantfile

Vagrant.configure("2") do |config|

    config.vm.define "dev1" do |dev1|
      dev1.vm.hostname = "dev1"
      dev1.vm.box = "dev1"
      dev1.vm.network "private_network", ip: "192.168.33.11"
    end

    config.vm.define "dev2" do |dev2|
      dev2.vm.hostname = "dev2"
      dev2.vm.box = "dev2"
      dev2.vm.network "private_network", ip:"172.16.1.2"
    end
end

In your case I am not sure why you have added the box as dev1 and dev2. It seems you have some confusion between the vagrant box and the VM.

I would recomment to leave the Vagrantfile as you have with reference of the bento boxes, removing the dev1/2 boxes and just run vagrant up. Vagrant will download the bento boxes, adding them to your config and will spin up dev1 and dev2 virtual machine.

Upvotes: 1

Related Questions