deploy in virtual box

ubuntu 16.04

mkdir test
cd test
vagrant init ubuntu/xenial64
vagrant up --provider virtualbox

ubuntu 14.04

#only one time
vagrant box add ubuntu14.04

mkdir test
cd test
vagrant init ubuntu14.04 
vagrant up

ubuntu 12.04

mkdir test
cd test
# download the configuration file 
vagrant init precise64
vagrant up
# the first time will be necessary download the operative system of the machines

# to login inside
vagrant ssh 

# to destroy the environment
vagrant destroy

# see the status
vagrant status

reload the machine

vagrant reload

halts the machine, and then starts the machine again with the new configuration. It skips the initial step to clone the box, since the machine is already created.

take at look inside the first Vagrantfile

cat Vagrantfile | grep -v "#"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| = "precise64"
  config.vm.box_url = ""

change network configuration

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

shared folder

basic configuration do |config|
# ...
  config.vm.share_folder "v-root", "/foo", "."
  • "v-root" : is the name of the default shared folder , you need to put to override the configuration
  • "/foo" : destination folder on the virtual machine
  • "." : is the directory where take the source
another directory do |config|
  # ...
  config.vm.share_folder "data", "/data", "./data"
note on the shared folder

Shared folders incur a heavy performance penalty within the virtual machine when there is heavy I/O, so they should only be used for source files. Any compilation step, database files, and so on should be done outside the shared folder filesystem inside the guest filesystem itself.


forward port

Vagrant.configure("2") do |config| "forwarded_port", guest: 80, host: 8080

forward port 80 on the guest to port 8080 on the host. This means from my machine in my browser i write http://localhost:8080 and I will connect with the web server (for example) listen on 80 of the virtual machine.


$ vagrant suspend
[default] Saving VM state and suspending execution...
$ vagrant status
Current machine states:
saved (virtualbox)

Suspending the guest machine will save the current running state of the machine and
stop it. The machine can then later be resumed from this exact suspended state.
With suspending, it is more like freezing time

to resume

vagrant up 
vagrant resume.


$ vagrant halt
[default] Attempting graceful shutdown of VM...
$ vagrant status
Current machine states:
poweroff (virtualbox)

Halting the guest machine will shut it down, like a normal computer. The machine can
then later be resumed via a normal boot up process, as if hitting the power button
This allows the guest to execute a proper shutdown
sequence, cleaning up all resources and safely shutting down.
If Vagrant is unable to gracefully shut down the machine, it will forcefully shut it down.

to resume

vagrant up


$ vagrant destroy
Are you sure you want to destroy the 'default' VM? [y/N] y
[default] Forcing shutdown of VM...
[default] Destroying VM and associated drives...
Working with the Vagrant Machine
$ vagrant status
Current machine states:
not created (virtualbox)

if you don't wont ask

vagrant destroy --force

deploy in ec2

First Run

source guide

code tested ubuntu desktop 12.04

full install in ubuntu 14.04 server

remove all the previous versions 
download the last package from here
dpkg -i vagrant*.deb
apt-get install vagrant
apt-get install build-essential
vagrant plugin install vagrant-aws
sudo vagrant plugin install vagrant-aws

we need to do like sudo because it needs to install gems

install dummy box

vagrant box add dummy

create the working directory

 mkdir testaws
$ cd testaws
$ vagrant init

this will create a Vagrantfile where put the info to edit

configure the bash variable
at the end of ~/.bashrc add


and after
source ~/.bashrc

it is convenient delete the content of the vagrant file and replace with this

Vagrant.configure("2") do |config| = "ubuntu_aws"
  config.vm.box_url = ""
  config.vm.provider :aws do |aws, override|

    aws.keypair_name = "namekey"
    override.ssh.private_key_path = "/home/giuseppe/pem/namekey.pem"
    override.ssh.username = "ubuntu"

    aws.block_device_mapping = [{ 'DeviceName' => '/dev/sda1', 'Ebs.VolumeSize' => 100 }]

    aws.instance_type = "t1.micro"
    aws.region = "us-west-2"
    aws.ami = "ami-e32556d3"

  • you must create before the keypair and download the key
  • you need also to choose a region and and choose an aws.ami for ubuntu this is a very good locator if you want use t1.micro instance type must be ebs
  • this config file assign the default security group is in this security group there is not the ssh from your location the state of creation will be always (or you can specify in the options to use a private ip that can be in the security group of the vpc but I have not yet tested this)
==> default: Waiting for SSH to become available...
deploy the machine in amazon
vagrant up --provider=aws

Bringing machine 'default' up with 'aws' provider...
[fog][WARNING] Unable to load the 'unf' gem. Your AWS strings may not be properly encoded.
==> default: HandleBoxUrl middleware is deprecated. Use HandleBox instead.
==> default: This is a bug with the provider. Please contact the creator
==> default: of the provider you use to fix this.
==> default: Warning! The AWS provider doesn't support any of the Vagrant
==> default: high-level network configurations (``). They
==> default: will be silently ignored.
==> default: Launching an instance with the following settings...
==> default:  -- Type: t1.micro
==> default:  -- AMI: ami-e32556d3
==> default:  -- Region: us-west-2
==> default:  -- Keypair: namekey
==> default:  -- Block Device Mapping: []
==> default:  -- Terminate On Shutdown: false
==> default:  -- Monitoring: false
==> default:  -- EBS optimized: false
==> default: Waiting for instance to become "ready"...
==> default: Waiting for SSH to become available...
==> default: Machine is booted and ready for use!
==> default: Rsyncing folder: /home/giuseppe/vagrant/testaws/ => /vagrant
vagrant ssh

advanced use

real parameters

The parameter of configuration can be read here the official documents but to read the real parameters and field available in your config take a look to this file


some useful code

for add tags and for vpc

    aws.tags = {
     'Name' => 'Test Vagrant machine',
     'type' => 'software',

    ## vpc configuration ###
    aws.elastic_ip = true
    aws.subnet_id = "subnet-123456a89" 
    aws.security_groups = "sg-1a23d56f"

it is not necessary the vpc id because there is the subnet_id , of course you need to setup the subnet and security group before.
Vagrant try always to access using the public ip so the security group rule must be open for my location

deploy in rackspace

A simple VagrantFile

usernameinrackspace = "mypersonaleusername"
apikeyinrackspace = "******"

# Ubuntu 14.04 LTS (Trusty Tahr)
imagechoosen = "e19a734c-c7e6-443a-830c-242209c4d65d"

#2GB Standard Instance
flavorchoosen = "4"

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| = "dummy"    
  config.vm.hostname = machinename
  config.ssh.port ="22"

  config.ssh.private_key_path = "~/.ssh/id_rsa"

  config.vm.provider :rackspace do |rs|
    rs.username        = usernameinrackspace
    rs.api_key         = apikeyinrackspace
    rs.flavor          = flavorchoosen
    rs.image           = imagechoosen
    rs.public_key_path = "~/.ssh/"
    rs.rackspace_region = :ord
    rs.server_name = machinename

To execute the command below you need before , to setup the credential in the VagrantFile

You can obtain a list of image available with this command

giuseppe@peppelaptop> vagrant rackspace images list
==> default: Image ID                             Image Name
==> default: 9c6765df-7fe4-4fd9-8308-a78faf399651 Ubuntu 10.04 LTS (Lucid Lynx)
==> default: 2f85a777-9ffd-4b49-a60e-1155ceb93a5e Ubuntu 12.04 LTS (Precise Pangolin)
==> default: ea322e55-0a03-48d6-b812-d9cf77fd05e7 Ubuntu 12.04 LTS (Precise Pangolin) (PVHVM)
==> default: e19a734c-c7e6-443a-830c-242209c4d65d Ubuntu 14.04 LTS (Trusty Tahr)
==> default: cc6e0096-84f9-4beb-a21e-d80a11a769d8 Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)

To obtain a list of Flavor available

giuseppe@peppelaptop> vagrant rackspace flavors
==> default: Flavor ID                            Flavor Name
==> default: 2                                    512MB Standard Instance
==> default: 3                                    1GB Standard Instance
==> default: 4                                    2GB Standard Instance
==> default: 5                                    4GB Standard Instance
==> default: 6                                    8GB Standard Instance
==> default: 7                                    15GB Standard Instance
==> default: 8                                    30GB Standard Instance
==> default: performance1-1                       1 GB Performance
==> default: performance1-2                       2 GB Performance
==> default: performance1-4                       4 GB Performance
==> default: performance1-8                       8 GB Performance
==> default: performance2-120                     120 GB Performance
==> default: performance2-15                      15 GB Performance
==> default: performance2-30                      30 GB Performance
==> default: performance2-60                      60 GB Performance
==> default: performance2-90                      90 GB Performance

after that you can run

vagrant up --provider=rackspace


if you have ssl problems probably you have a proxy in the middle.

SSL certificate problem: self signed certificate in certificate chain
More details here:

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.

you need to run the command with the insecure option
vagrant box add ubuntu14.04
/trusty/current/ --insecure
Salvo diversa indicazione, il contenuto di questa pagina è sotto licenza Creative Commons Attribution-ShareAlike 3.0 License