Search code examples
vagrantvirtual-machinevirtualboxbox

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.


Solution

  • 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.