Table of Content
find out vagrant box for latest release Ubuntu 16.10 (Yakkety Yak)
search Yakkety Yak from https://atlas.hashicorp.com/ubuntu
will find below box:
https://atlas.hashicorp.com/ubuntu/boxes/yakkety64
will see command for virtualbox:
vagrant init ubuntu/yakkety64; vagrant up --provider virtualbox
vagrant up
$ cd ~/vagrant $ vagrant init ubuntu/yakkety64; vagrant up --provider virtualbox AVagrantfile
has been placed in this directory. You are now ready tovagrant up
your first virtual environment! Please read the comments in the Vagrantfile as well as documentation onvagrantup.com
for more information on using Vagrant. Bringing machine 'default' up with 'virtualbox' provider... ==> default: Box 'ubuntu/yakkety64' could not be found. Attempting to find and install... default: Box Provider: virtualbox default: Box Version: >= 0 ==> default: Loading metadata for box 'ubuntu/yakkety64' default: URL: https://atlas.hashicorp.com/ubuntu/yakkety64 ==> default: Adding box 'ubuntu/yakkety64' (v20161208.0.0) for provider: virtualbox default: Downloading: https://atlas.hashicorp.com/ubuntu/boxes/yakkety64/versions/20161208.0.0/providers/virtualbox.box default: Progress: 100% (Rate: 266k/s, Estimated time remaining: --:--:--) ==> default: Successfully added box 'ubuntu/yakkety64' (v20161208.0.0) for 'virtualbox'! ==> default: Importing base box 'ubuntu/yakkety64'... ==> default: Matching MAC address for NAT networking... ==> default: Checking if box 'ubuntu/yakkety64' is up to date... ==> default: Setting the name of the VM: vagrant_default_1481401982784_54453 ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 22 (guest) => 2222 (host) (adapter 1) ==> default: Running 'pre-boot' VM customizations... ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: ubuntu default: SSH auth method: password default: Warning: Remote connection disconnect. Retrying... default: default: Inserting generated public key within guest... default: Removing insecure key from the guest if it's present... default: Key inserted! Disconnecting and reconnecting using new SSH key... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Mounting shared folders... default: /vagrant => L:/portabledevops/msys64/home//vagrant
ssh to vagrant machine
$ vagrant ssh Welcome to Ubuntu 16.10 (GNU/Linux 4.8.0-30-generic x86_64) ubuntu@ubuntu-yakkety:~$ uname -a Linux ubuntu-yakkety 4.8.0-30-generic #32-Ubuntu SMP Fri Dec 2 03:43:27 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
vagrant mount sharing folder
add this line to Vagrantfile
config.vm.synced_folder "../testgo", "/vagrant_testgo"
../testgo is on host
/vagrant_testgo is on guest vm
$ vagrant reload $ vagrant up
will see in log,
==> default: Mounting shared folders... default: /vagrant => L:/portabledevops/msys64/home//vagrant default: /vagrant_testgo => L:/portabledevops/msys64/home/ /testgo
vagrant network forwarding
add this line to Vagrantfile
config.vm.network "forwarded_port", guest: 80, host: 8888
$ vagrant reload $ vagrant up
will see in log,
default: Adapter 1: nat ==> default: Forwarding ports... default: 80 (guest) => 8888 (host) (adapter 1) default: 22 (guest) => 2222 (host) (adapter 1)
Let’s test port forwarding by launching simple web server in guest vm:
$ sudo apt install python-minimal $ sudo python -m SimpleHTTPServer 80
then from host, type in browser:
http://localhost:8888
vagrant provision script
provision.sh located at Vagrantfile project folder,
#!/usr/bin/env bash echo "Installing Apache and setting it up..." apt-get update >/dev/null 2>&1 apt-get install -y apache2 >/dev/null 2>&1 rm -rf /var/www ln -fs /vagrant /var/www
add line to Vagrantfile:
config.vm.provision "shell", path: "provision.sh"
vagrant up with provisioning
$ vagrant up --provision Bringing machine 'default' up with 'virtualbox' provider... ==> default: Checking if box 'ubuntu/yakkety64' is up to date... ==> default: A newer version of the box 'ubuntu/yakkety64' is available! You currently ==> default: have version '20161129.0.0'. The latest is version '20161208.0.0'. Run ==> default:vagrant box update
to update. ==> default: Clearing any previously set forwarded ports... ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 80 (guest) => 8888 (host) (adapter 1) default: 22 (guest) => 2222 (host) (adapter 1) ==> default: Running 'pre-boot' VM customizations... ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: ubuntu default: SSH auth method: password default: Warning: Remote connection disconnect. Retrying... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Mounting shared folders... default: /vagrant => L:/portabledevops/cygwin64/home//vagrant ==> default: Running provisioner: shell... default: Running: L:/portabledevops/cygwin64/tmp/vagrant-shell20161210-6864-2qvtkt.sh ==> default: mesg: ==> default: ttyname failed ==> default: : ==> default: Inappropriate ioctl for device ==> default: Installing Apache and setting it up...