Rahul Shrivastava
Rahul Shrivastava

Reputation: 1411

How to install Vagrant VM from local

I was learning Udacity course and they asked me to install Vagrant. But due to large size of .box file I first downloaded it to local from other network and i got this tar file trusty-server-cloudimg-i386-vagrant-disk1.tar. They asked me to download their folder fullstack. This folder consists of following structure:

|--fullstack
    |--vagrant
        |--.vagrant
        |--catalog
        |--forum
            |--forum.py
            |--forum.sql
            |--forumdb.py
        |--tournament
            |--tournament.py
            |--tournament.sql
            |--tournament_test.py
        |--pg_config
        |--Vagrantfile

Vagrant You can see how they are doing from this link. Now when I am using vagrant up on git bash by going to the location fullstack/vagrant following codes are getting up:

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'ubuntu/trusty32' could not be found. Attempting to find and in
stall...
    default: Box Provider: virtualbox
    defa

ult: Box Version: >= 0
==> default: Loading metadata for box 'ubuntu/trusty32'
    default: URL: https://atlas.hashicorp.com/ubuntu/trusty32
==> default: Adding box 'ubuntu/trusty32' (v20150818.0.0) for provider: virtualb
ox

Now as you can see in the code downwards it is trying to download .box file from online which I have downloaded on local and I have that on my drive. I want to edit some config file such that when I use vagrant up it should uses the local file trusty-server-cloudimg-i386-vagrant-disk1.tar file to install and should not go for downloading the online file

default: Downloading: https://atlas.hashicorp.com/ubuntu/boxes/trusty32/versions/20150818.0.0/providers/virtualbox.box
    ==> default: Box download is resuming from prior download progress
        default: Progress: 0% (Rate: 13410/s, Estimated time remaining: 5:35:56))

If still some information required please ask me in comment I will update my question.

Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.provision "shell", path: "pg_config.sh"
  # config.vm.box = "hashicorp/precise32"
  config.vm.box = "ubuntu/trusty32"
  config.vm.network "forwarded_port", guest: 8000, host: 8000
  config.vm.network "forwarded_port", guest: 8080, host: 8080
  config.vm.network "forwarded_port", guest: 5000, host: 5000
end

pg_config.sh :

apt-get -qqy update
apt-get -qqy install postgresql python-psycopg2
apt-get -qqy install python-flask python-sqlalchemy
apt-get -qqy install python-pip
pip install bleach
pip install oauth2client
pip install requests
pip install httplib2
su postgres -c 'createuser -dRS vagrant'
su vagrant -c 'createdb'
su vagrant -c 'createdb forum'
su vagrant -c 'psql forum -f /vagrant/forum/forum.sql'

vagrantTip="[35m[1mThe shared directory is located at /vagrant\nTo access your shared files: cd /vagrant(B[m"
echo -e $vagrantTip > /etc/motd

When I am trying to add like this I getting following error:

$ vagrant box add mybox C:\Users\Rahul\Downloads\trusty-server-cloudimg-i386-va
grant-disk1.tar
c:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/uri/generic.rb:214:in `initialize':
 the scheme file does not accept registry part: C:UsersRahulDownloadstrusty-serv
er-cloudimg-i386-vagrant-disk1.tar (or bad hostname?) (URI::InvalidURIError)
        from c:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/uri/common.rb:218:in `
new'
        from c:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/uri/common.rb:218:in `
parse'
        from c:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/uri/common.rb:747:in `
parse'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/a
ction/builtin/box_add.rb:465:in `metadata_url?'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/a
ction/builtin/box_add.rb:77:in `block in call'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/a
ction/builtin/box_add.rb:75:in `map'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/a
ction/builtin/box_add.rb:75:in `call'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/a
ction/warden.rb:34:in `call'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/a
ction/builder.rb:116:in `call'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/a
ction/runner.rb:66:in `block in run'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/u
til/busy.rb:19:in `busy'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/a
ction/runner.rb:66:in `run'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/plugins/comma
nds/box/command/add.rb:89:in `execute'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/plugins/comma
nds/box/command/root.rb:61:in `execute'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/c
li.rb:42:in `execute'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/e
nvironment.rb:301:in `cli'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/bin/vagrant:1
74:in `<main>'

Edited Added some error:

$ vagrant box add mybox C:/Udacity/trusty-server-cloudimg-i386-vagrant-disk1.ta
r
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'mybox' (v0) for provider:
    box: Unpacking necessary files from: file://C:/Udacity/trusty-server-cloudim
g-i386-vagrant-disk1.tar
    box:
An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.

Couldn't open file /Udacity/trusty-server-cloudimg-i386-vagrant-disk1.tar

Upvotes: 1

Views: 4974

Answers (1)

rockcode
rockcode

Reputation: 353

You might have to add the box as below. Refer http://docs.vagrantup.com/v2/cli/box.html

vagrant box add yourbox file:///box-file-location/yourbox.box
vagrant init yourbox
vagrant up

Upvotes: 5

Related Questions