devops hackathon - session 1: vagrant

37
Vagrant hackaton Session Activities can be found here: https://github.com/akranga/devops-hackathon-1

Upload: antons-kranga

Post on 19-Aug-2014

387 views

Category:

Engineering


8 download

DESCRIPTION

Current session guides through Vagrant. Shows some tips and tricks and targeted to software developers. Practical activities can be found here: https://github.com/akranga/devops-hackathon-1

TRANSCRIPT

Page 1: DevOps Hackathon - Session 1: Vagrant

Vagrant hackaton

Session Activities can be found herehttpsgithubcomakrangadevops-hackathon-1

Vagrant

- Vagrant will mange VM for you

- Describe VM in configuration file

- Can put configuration in Source Control

- You can allow other to contribute

- You have full control on VM

Vagrant

- Ruby powered command line interface to VM hosted in your Computer

- Supports multiple VM providers (VirtualBox by default)

- Allows to create reproducible and portable environments

Vagrant

- Supports run of Multi-VM environments

- Allows to createrestore snapshots of VM

- Allows package environment

- Environment configuration stored in file(you can put it in git)

Installing Vagrant- Download and install latest VirtualBox for your OS

httpswwwvirtualboxorgwikiDownloads

- Download and install latest vagrant for your OShttpwwwvagrantupcomdownloadshtml

- Update PATH Environment System Variable Add entries- VirtualBox location

- CProgram FilesOracleVirtualBox

- Vagrant location- CDevOpsvagrantbin

- Might require extra directories- CDevOpsvagrantembeddedbin- CDevOpsvagrantembeddedmingwbin- CDevOpsvagrantembeddedgemsbin

Vagrant Components- Command Line Interface

- Vagrantfile

- Boxes

- Synced Folder

- Provisioning

- Multi Machine

- Providers

Command Line InterfaceVagrant basic operating model through CLI vagrant command

Running any vagrant subcommand with --help or ndashh prints context help

$ vagrant init

$ vagrant up

$ vagrant halt

$ vagrant reload

$ vagrant provision

$ vagrant destroy

$ vagrant ssh

$ vagrant ssh-config

Create initial Vagrant configuratoinStart or create VM if not existsPower down VM

Restart VM (useful when you change config)

Run Chef or Puppet scripts

Destroy VM as it never existed

Connect to VM if it is running

Prints SSH configuration

Command Line Interface

shell$ vagrant box list

$ vagrant box add

$ vagrant box remove

$ vagrant box repackage

$ vagrant box outdated

$ vagrant box update

List all vagrant environments on your PCAdd basebox record to vagrant registryRemove basebox (doesnrsquot terminate VM)

Make a snapshot of your VM

Deprecates the VM

Checks and updates a VM if it is out-dated

Additional commands to manage your vagrant environments

VagrantfileAll VM configuration stored in Ruby DSL file This file can be placed in git

When you run vagrant up Vagrant will check following directories

Vagrantfile homemitchellhprojectsfooVagrantfile homemitchellhprojectsVagrantfile homemitchellhVagrantfile homeVagrantfile Vagrantfile

VAGRANT_CWD to change directory where Vagrant is looking for configuration

Boxes

VagrantfileVagrantconfigure 2 do |config|

configvmbox = ldquomy-vm

configvmbox_url = ldquobox-url

end

Minimal Vagrantfile looks like this

Vagrant file contains API versioning

Vagrantfile (cont)Vagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

How many machines will run this file

Modifying scriptsconfigvm ndash to mange VM parameters

Vagrantfileconfigvmbox

configvmcheck_update

configvmbox_url

configvmbox_version

configvmboxhostname

configvmprovider

cofnigvmsynced_folder

Name to be associated with boxBy default true Can disable update checksURL of the VM to downloadVersion of the basebox file

Hostname of the VM

By default VirtualBox Can be other

By default current host dir mounted as Vagrant Can map additional directory inside VM

Modifying scriptsconfigssh ndash to customize SSH behavior

Vagrantfileconfigsshusername

configsshpassword

configsshprivate_key_path

configsshinsert_key

configsshshell

By default vagrantNo pass by default

Path to your SSH key By default homevagrantdinsecure_private_key

By default true Can disable to use passShell to open when ssh By default bash -l

BoxesTo create a VM Vagrant needs a basebox file which is typically Just Enough Operating System

Baseboxes can be downloaded from Community websiteswwwvagrantboxes Offsite for Vagrant boxes

httpopscodegithubiobento Vagrant boxes optimized for Chef

You can create your own box using- Packer (httppackerio)- Packer templates for Chef optimized boxes can be found

httpsgithubcomopscodebento

Synced FolderTo enable Vagrant to sync files at your Host and Guest machine

By default mapped directory vagrant

Permissions all files in synced folder are 0777

Vagrant PluginsVagrant is extremely pluggable

You can addcostomize almost everything in Vagrant (such as add VMWare AWS or Docker providers) Chef or Puppet provisioning etc

Vagrant has tons of plugins Official hosted here httpsgithubcommitchellhvagranttreemasterplugins

Dog Food API for Vagrant plugins httpenwikipediaorgwikiEating_your_own_dog_food

Most useful Plugins- vagrant-omnibus Chef for Vagrant VMs- vagrant-cachier Cache for packages (can be reused across

VMs)- vagrant-berkshelf Enable Chef cookbook dependency

mechanism

Vagrant plugins commandCLI to manage vagrant plugins

Will be installed in homevagrantdgemsShell

$ vagrant plugin install

$ vagrant plugin list

$ vagrant plugin uninstall

$ vagrant plugin update

Install vagrant pluginList of installed pluginsErase plugin

Check plugin and update with newer version

Activity 1Run a vagrant box

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 2: DevOps Hackathon - Session 1: Vagrant

Vagrant

- Vagrant will mange VM for you

- Describe VM in configuration file

- Can put configuration in Source Control

- You can allow other to contribute

- You have full control on VM

Vagrant

- Ruby powered command line interface to VM hosted in your Computer

- Supports multiple VM providers (VirtualBox by default)

- Allows to create reproducible and portable environments

Vagrant

- Supports run of Multi-VM environments

- Allows to createrestore snapshots of VM

- Allows package environment

- Environment configuration stored in file(you can put it in git)

Installing Vagrant- Download and install latest VirtualBox for your OS

httpswwwvirtualboxorgwikiDownloads

- Download and install latest vagrant for your OShttpwwwvagrantupcomdownloadshtml

- Update PATH Environment System Variable Add entries- VirtualBox location

- CProgram FilesOracleVirtualBox

- Vagrant location- CDevOpsvagrantbin

- Might require extra directories- CDevOpsvagrantembeddedbin- CDevOpsvagrantembeddedmingwbin- CDevOpsvagrantembeddedgemsbin

Vagrant Components- Command Line Interface

- Vagrantfile

- Boxes

- Synced Folder

- Provisioning

- Multi Machine

- Providers

Command Line InterfaceVagrant basic operating model through CLI vagrant command

Running any vagrant subcommand with --help or ndashh prints context help

$ vagrant init

$ vagrant up

$ vagrant halt

$ vagrant reload

$ vagrant provision

$ vagrant destroy

$ vagrant ssh

$ vagrant ssh-config

Create initial Vagrant configuratoinStart or create VM if not existsPower down VM

Restart VM (useful when you change config)

Run Chef or Puppet scripts

Destroy VM as it never existed

Connect to VM if it is running

Prints SSH configuration

Command Line Interface

shell$ vagrant box list

$ vagrant box add

$ vagrant box remove

$ vagrant box repackage

$ vagrant box outdated

$ vagrant box update

List all vagrant environments on your PCAdd basebox record to vagrant registryRemove basebox (doesnrsquot terminate VM)

Make a snapshot of your VM

Deprecates the VM

Checks and updates a VM if it is out-dated

Additional commands to manage your vagrant environments

VagrantfileAll VM configuration stored in Ruby DSL file This file can be placed in git

When you run vagrant up Vagrant will check following directories

Vagrantfile homemitchellhprojectsfooVagrantfile homemitchellhprojectsVagrantfile homemitchellhVagrantfile homeVagrantfile Vagrantfile

VAGRANT_CWD to change directory where Vagrant is looking for configuration

Boxes

VagrantfileVagrantconfigure 2 do |config|

configvmbox = ldquomy-vm

configvmbox_url = ldquobox-url

end

Minimal Vagrantfile looks like this

Vagrant file contains API versioning

Vagrantfile (cont)Vagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

How many machines will run this file

Modifying scriptsconfigvm ndash to mange VM parameters

Vagrantfileconfigvmbox

configvmcheck_update

configvmbox_url

configvmbox_version

configvmboxhostname

configvmprovider

cofnigvmsynced_folder

Name to be associated with boxBy default true Can disable update checksURL of the VM to downloadVersion of the basebox file

Hostname of the VM

By default VirtualBox Can be other

By default current host dir mounted as Vagrant Can map additional directory inside VM

Modifying scriptsconfigssh ndash to customize SSH behavior

Vagrantfileconfigsshusername

configsshpassword

configsshprivate_key_path

configsshinsert_key

configsshshell

By default vagrantNo pass by default

Path to your SSH key By default homevagrantdinsecure_private_key

By default true Can disable to use passShell to open when ssh By default bash -l

BoxesTo create a VM Vagrant needs a basebox file which is typically Just Enough Operating System

Baseboxes can be downloaded from Community websiteswwwvagrantboxes Offsite for Vagrant boxes

httpopscodegithubiobento Vagrant boxes optimized for Chef

You can create your own box using- Packer (httppackerio)- Packer templates for Chef optimized boxes can be found

httpsgithubcomopscodebento

Synced FolderTo enable Vagrant to sync files at your Host and Guest machine

By default mapped directory vagrant

Permissions all files in synced folder are 0777

Vagrant PluginsVagrant is extremely pluggable

You can addcostomize almost everything in Vagrant (such as add VMWare AWS or Docker providers) Chef or Puppet provisioning etc

Vagrant has tons of plugins Official hosted here httpsgithubcommitchellhvagranttreemasterplugins

Dog Food API for Vagrant plugins httpenwikipediaorgwikiEating_your_own_dog_food

Most useful Plugins- vagrant-omnibus Chef for Vagrant VMs- vagrant-cachier Cache for packages (can be reused across

VMs)- vagrant-berkshelf Enable Chef cookbook dependency

mechanism

Vagrant plugins commandCLI to manage vagrant plugins

Will be installed in homevagrantdgemsShell

$ vagrant plugin install

$ vagrant plugin list

$ vagrant plugin uninstall

$ vagrant plugin update

Install vagrant pluginList of installed pluginsErase plugin

Check plugin and update with newer version

Activity 1Run a vagrant box

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 3: DevOps Hackathon - Session 1: Vagrant

Vagrant

- Ruby powered command line interface to VM hosted in your Computer

- Supports multiple VM providers (VirtualBox by default)

- Allows to create reproducible and portable environments

Vagrant

- Supports run of Multi-VM environments

- Allows to createrestore snapshots of VM

- Allows package environment

- Environment configuration stored in file(you can put it in git)

Installing Vagrant- Download and install latest VirtualBox for your OS

httpswwwvirtualboxorgwikiDownloads

- Download and install latest vagrant for your OShttpwwwvagrantupcomdownloadshtml

- Update PATH Environment System Variable Add entries- VirtualBox location

- CProgram FilesOracleVirtualBox

- Vagrant location- CDevOpsvagrantbin

- Might require extra directories- CDevOpsvagrantembeddedbin- CDevOpsvagrantembeddedmingwbin- CDevOpsvagrantembeddedgemsbin

Vagrant Components- Command Line Interface

- Vagrantfile

- Boxes

- Synced Folder

- Provisioning

- Multi Machine

- Providers

Command Line InterfaceVagrant basic operating model through CLI vagrant command

Running any vagrant subcommand with --help or ndashh prints context help

$ vagrant init

$ vagrant up

$ vagrant halt

$ vagrant reload

$ vagrant provision

$ vagrant destroy

$ vagrant ssh

$ vagrant ssh-config

Create initial Vagrant configuratoinStart or create VM if not existsPower down VM

Restart VM (useful when you change config)

Run Chef or Puppet scripts

Destroy VM as it never existed

Connect to VM if it is running

Prints SSH configuration

Command Line Interface

shell$ vagrant box list

$ vagrant box add

$ vagrant box remove

$ vagrant box repackage

$ vagrant box outdated

$ vagrant box update

List all vagrant environments on your PCAdd basebox record to vagrant registryRemove basebox (doesnrsquot terminate VM)

Make a snapshot of your VM

Deprecates the VM

Checks and updates a VM if it is out-dated

Additional commands to manage your vagrant environments

VagrantfileAll VM configuration stored in Ruby DSL file This file can be placed in git

When you run vagrant up Vagrant will check following directories

Vagrantfile homemitchellhprojectsfooVagrantfile homemitchellhprojectsVagrantfile homemitchellhVagrantfile homeVagrantfile Vagrantfile

VAGRANT_CWD to change directory where Vagrant is looking for configuration

Boxes

VagrantfileVagrantconfigure 2 do |config|

configvmbox = ldquomy-vm

configvmbox_url = ldquobox-url

end

Minimal Vagrantfile looks like this

Vagrant file contains API versioning

Vagrantfile (cont)Vagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

How many machines will run this file

Modifying scriptsconfigvm ndash to mange VM parameters

Vagrantfileconfigvmbox

configvmcheck_update

configvmbox_url

configvmbox_version

configvmboxhostname

configvmprovider

cofnigvmsynced_folder

Name to be associated with boxBy default true Can disable update checksURL of the VM to downloadVersion of the basebox file

Hostname of the VM

By default VirtualBox Can be other

By default current host dir mounted as Vagrant Can map additional directory inside VM

Modifying scriptsconfigssh ndash to customize SSH behavior

Vagrantfileconfigsshusername

configsshpassword

configsshprivate_key_path

configsshinsert_key

configsshshell

By default vagrantNo pass by default

Path to your SSH key By default homevagrantdinsecure_private_key

By default true Can disable to use passShell to open when ssh By default bash -l

BoxesTo create a VM Vagrant needs a basebox file which is typically Just Enough Operating System

Baseboxes can be downloaded from Community websiteswwwvagrantboxes Offsite for Vagrant boxes

httpopscodegithubiobento Vagrant boxes optimized for Chef

You can create your own box using- Packer (httppackerio)- Packer templates for Chef optimized boxes can be found

httpsgithubcomopscodebento

Synced FolderTo enable Vagrant to sync files at your Host and Guest machine

By default mapped directory vagrant

Permissions all files in synced folder are 0777

Vagrant PluginsVagrant is extremely pluggable

You can addcostomize almost everything in Vagrant (such as add VMWare AWS or Docker providers) Chef or Puppet provisioning etc

Vagrant has tons of plugins Official hosted here httpsgithubcommitchellhvagranttreemasterplugins

Dog Food API for Vagrant plugins httpenwikipediaorgwikiEating_your_own_dog_food

Most useful Plugins- vagrant-omnibus Chef for Vagrant VMs- vagrant-cachier Cache for packages (can be reused across

VMs)- vagrant-berkshelf Enable Chef cookbook dependency

mechanism

Vagrant plugins commandCLI to manage vagrant plugins

Will be installed in homevagrantdgemsShell

$ vagrant plugin install

$ vagrant plugin list

$ vagrant plugin uninstall

$ vagrant plugin update

Install vagrant pluginList of installed pluginsErase plugin

Check plugin and update with newer version

Activity 1Run a vagrant box

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 4: DevOps Hackathon - Session 1: Vagrant

Vagrant

- Supports run of Multi-VM environments

- Allows to createrestore snapshots of VM

- Allows package environment

- Environment configuration stored in file(you can put it in git)

Installing Vagrant- Download and install latest VirtualBox for your OS

httpswwwvirtualboxorgwikiDownloads

- Download and install latest vagrant for your OShttpwwwvagrantupcomdownloadshtml

- Update PATH Environment System Variable Add entries- VirtualBox location

- CProgram FilesOracleVirtualBox

- Vagrant location- CDevOpsvagrantbin

- Might require extra directories- CDevOpsvagrantembeddedbin- CDevOpsvagrantembeddedmingwbin- CDevOpsvagrantembeddedgemsbin

Vagrant Components- Command Line Interface

- Vagrantfile

- Boxes

- Synced Folder

- Provisioning

- Multi Machine

- Providers

Command Line InterfaceVagrant basic operating model through CLI vagrant command

Running any vagrant subcommand with --help or ndashh prints context help

$ vagrant init

$ vagrant up

$ vagrant halt

$ vagrant reload

$ vagrant provision

$ vagrant destroy

$ vagrant ssh

$ vagrant ssh-config

Create initial Vagrant configuratoinStart or create VM if not existsPower down VM

Restart VM (useful when you change config)

Run Chef or Puppet scripts

Destroy VM as it never existed

Connect to VM if it is running

Prints SSH configuration

Command Line Interface

shell$ vagrant box list

$ vagrant box add

$ vagrant box remove

$ vagrant box repackage

$ vagrant box outdated

$ vagrant box update

List all vagrant environments on your PCAdd basebox record to vagrant registryRemove basebox (doesnrsquot terminate VM)

Make a snapshot of your VM

Deprecates the VM

Checks and updates a VM if it is out-dated

Additional commands to manage your vagrant environments

VagrantfileAll VM configuration stored in Ruby DSL file This file can be placed in git

When you run vagrant up Vagrant will check following directories

Vagrantfile homemitchellhprojectsfooVagrantfile homemitchellhprojectsVagrantfile homemitchellhVagrantfile homeVagrantfile Vagrantfile

VAGRANT_CWD to change directory where Vagrant is looking for configuration

Boxes

VagrantfileVagrantconfigure 2 do |config|

configvmbox = ldquomy-vm

configvmbox_url = ldquobox-url

end

Minimal Vagrantfile looks like this

Vagrant file contains API versioning

Vagrantfile (cont)Vagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

How many machines will run this file

Modifying scriptsconfigvm ndash to mange VM parameters

Vagrantfileconfigvmbox

configvmcheck_update

configvmbox_url

configvmbox_version

configvmboxhostname

configvmprovider

cofnigvmsynced_folder

Name to be associated with boxBy default true Can disable update checksURL of the VM to downloadVersion of the basebox file

Hostname of the VM

By default VirtualBox Can be other

By default current host dir mounted as Vagrant Can map additional directory inside VM

Modifying scriptsconfigssh ndash to customize SSH behavior

Vagrantfileconfigsshusername

configsshpassword

configsshprivate_key_path

configsshinsert_key

configsshshell

By default vagrantNo pass by default

Path to your SSH key By default homevagrantdinsecure_private_key

By default true Can disable to use passShell to open when ssh By default bash -l

BoxesTo create a VM Vagrant needs a basebox file which is typically Just Enough Operating System

Baseboxes can be downloaded from Community websiteswwwvagrantboxes Offsite for Vagrant boxes

httpopscodegithubiobento Vagrant boxes optimized for Chef

You can create your own box using- Packer (httppackerio)- Packer templates for Chef optimized boxes can be found

httpsgithubcomopscodebento

Synced FolderTo enable Vagrant to sync files at your Host and Guest machine

By default mapped directory vagrant

Permissions all files in synced folder are 0777

Vagrant PluginsVagrant is extremely pluggable

You can addcostomize almost everything in Vagrant (such as add VMWare AWS or Docker providers) Chef or Puppet provisioning etc

Vagrant has tons of plugins Official hosted here httpsgithubcommitchellhvagranttreemasterplugins

Dog Food API for Vagrant plugins httpenwikipediaorgwikiEating_your_own_dog_food

Most useful Plugins- vagrant-omnibus Chef for Vagrant VMs- vagrant-cachier Cache for packages (can be reused across

VMs)- vagrant-berkshelf Enable Chef cookbook dependency

mechanism

Vagrant plugins commandCLI to manage vagrant plugins

Will be installed in homevagrantdgemsShell

$ vagrant plugin install

$ vagrant plugin list

$ vagrant plugin uninstall

$ vagrant plugin update

Install vagrant pluginList of installed pluginsErase plugin

Check plugin and update with newer version

Activity 1Run a vagrant box

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 5: DevOps Hackathon - Session 1: Vagrant

Installing Vagrant- Download and install latest VirtualBox for your OS

httpswwwvirtualboxorgwikiDownloads

- Download and install latest vagrant for your OShttpwwwvagrantupcomdownloadshtml

- Update PATH Environment System Variable Add entries- VirtualBox location

- CProgram FilesOracleVirtualBox

- Vagrant location- CDevOpsvagrantbin

- Might require extra directories- CDevOpsvagrantembeddedbin- CDevOpsvagrantembeddedmingwbin- CDevOpsvagrantembeddedgemsbin

Vagrant Components- Command Line Interface

- Vagrantfile

- Boxes

- Synced Folder

- Provisioning

- Multi Machine

- Providers

Command Line InterfaceVagrant basic operating model through CLI vagrant command

Running any vagrant subcommand with --help or ndashh prints context help

$ vagrant init

$ vagrant up

$ vagrant halt

$ vagrant reload

$ vagrant provision

$ vagrant destroy

$ vagrant ssh

$ vagrant ssh-config

Create initial Vagrant configuratoinStart or create VM if not existsPower down VM

Restart VM (useful when you change config)

Run Chef or Puppet scripts

Destroy VM as it never existed

Connect to VM if it is running

Prints SSH configuration

Command Line Interface

shell$ vagrant box list

$ vagrant box add

$ vagrant box remove

$ vagrant box repackage

$ vagrant box outdated

$ vagrant box update

List all vagrant environments on your PCAdd basebox record to vagrant registryRemove basebox (doesnrsquot terminate VM)

Make a snapshot of your VM

Deprecates the VM

Checks and updates a VM if it is out-dated

Additional commands to manage your vagrant environments

VagrantfileAll VM configuration stored in Ruby DSL file This file can be placed in git

When you run vagrant up Vagrant will check following directories

Vagrantfile homemitchellhprojectsfooVagrantfile homemitchellhprojectsVagrantfile homemitchellhVagrantfile homeVagrantfile Vagrantfile

VAGRANT_CWD to change directory where Vagrant is looking for configuration

Boxes

VagrantfileVagrantconfigure 2 do |config|

configvmbox = ldquomy-vm

configvmbox_url = ldquobox-url

end

Minimal Vagrantfile looks like this

Vagrant file contains API versioning

Vagrantfile (cont)Vagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

How many machines will run this file

Modifying scriptsconfigvm ndash to mange VM parameters

Vagrantfileconfigvmbox

configvmcheck_update

configvmbox_url

configvmbox_version

configvmboxhostname

configvmprovider

cofnigvmsynced_folder

Name to be associated with boxBy default true Can disable update checksURL of the VM to downloadVersion of the basebox file

Hostname of the VM

By default VirtualBox Can be other

By default current host dir mounted as Vagrant Can map additional directory inside VM

Modifying scriptsconfigssh ndash to customize SSH behavior

Vagrantfileconfigsshusername

configsshpassword

configsshprivate_key_path

configsshinsert_key

configsshshell

By default vagrantNo pass by default

Path to your SSH key By default homevagrantdinsecure_private_key

By default true Can disable to use passShell to open when ssh By default bash -l

BoxesTo create a VM Vagrant needs a basebox file which is typically Just Enough Operating System

Baseboxes can be downloaded from Community websiteswwwvagrantboxes Offsite for Vagrant boxes

httpopscodegithubiobento Vagrant boxes optimized for Chef

You can create your own box using- Packer (httppackerio)- Packer templates for Chef optimized boxes can be found

httpsgithubcomopscodebento

Synced FolderTo enable Vagrant to sync files at your Host and Guest machine

By default mapped directory vagrant

Permissions all files in synced folder are 0777

Vagrant PluginsVagrant is extremely pluggable

You can addcostomize almost everything in Vagrant (such as add VMWare AWS or Docker providers) Chef or Puppet provisioning etc

Vagrant has tons of plugins Official hosted here httpsgithubcommitchellhvagranttreemasterplugins

Dog Food API for Vagrant plugins httpenwikipediaorgwikiEating_your_own_dog_food

Most useful Plugins- vagrant-omnibus Chef for Vagrant VMs- vagrant-cachier Cache for packages (can be reused across

VMs)- vagrant-berkshelf Enable Chef cookbook dependency

mechanism

Vagrant plugins commandCLI to manage vagrant plugins

Will be installed in homevagrantdgemsShell

$ vagrant plugin install

$ vagrant plugin list

$ vagrant plugin uninstall

$ vagrant plugin update

Install vagrant pluginList of installed pluginsErase plugin

Check plugin and update with newer version

Activity 1Run a vagrant box

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 6: DevOps Hackathon - Session 1: Vagrant

Vagrant Components- Command Line Interface

- Vagrantfile

- Boxes

- Synced Folder

- Provisioning

- Multi Machine

- Providers

Command Line InterfaceVagrant basic operating model through CLI vagrant command

Running any vagrant subcommand with --help or ndashh prints context help

$ vagrant init

$ vagrant up

$ vagrant halt

$ vagrant reload

$ vagrant provision

$ vagrant destroy

$ vagrant ssh

$ vagrant ssh-config

Create initial Vagrant configuratoinStart or create VM if not existsPower down VM

Restart VM (useful when you change config)

Run Chef or Puppet scripts

Destroy VM as it never existed

Connect to VM if it is running

Prints SSH configuration

Command Line Interface

shell$ vagrant box list

$ vagrant box add

$ vagrant box remove

$ vagrant box repackage

$ vagrant box outdated

$ vagrant box update

List all vagrant environments on your PCAdd basebox record to vagrant registryRemove basebox (doesnrsquot terminate VM)

Make a snapshot of your VM

Deprecates the VM

Checks and updates a VM if it is out-dated

Additional commands to manage your vagrant environments

VagrantfileAll VM configuration stored in Ruby DSL file This file can be placed in git

When you run vagrant up Vagrant will check following directories

Vagrantfile homemitchellhprojectsfooVagrantfile homemitchellhprojectsVagrantfile homemitchellhVagrantfile homeVagrantfile Vagrantfile

VAGRANT_CWD to change directory where Vagrant is looking for configuration

Boxes

VagrantfileVagrantconfigure 2 do |config|

configvmbox = ldquomy-vm

configvmbox_url = ldquobox-url

end

Minimal Vagrantfile looks like this

Vagrant file contains API versioning

Vagrantfile (cont)Vagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

How many machines will run this file

Modifying scriptsconfigvm ndash to mange VM parameters

Vagrantfileconfigvmbox

configvmcheck_update

configvmbox_url

configvmbox_version

configvmboxhostname

configvmprovider

cofnigvmsynced_folder

Name to be associated with boxBy default true Can disable update checksURL of the VM to downloadVersion of the basebox file

Hostname of the VM

By default VirtualBox Can be other

By default current host dir mounted as Vagrant Can map additional directory inside VM

Modifying scriptsconfigssh ndash to customize SSH behavior

Vagrantfileconfigsshusername

configsshpassword

configsshprivate_key_path

configsshinsert_key

configsshshell

By default vagrantNo pass by default

Path to your SSH key By default homevagrantdinsecure_private_key

By default true Can disable to use passShell to open when ssh By default bash -l

BoxesTo create a VM Vagrant needs a basebox file which is typically Just Enough Operating System

Baseboxes can be downloaded from Community websiteswwwvagrantboxes Offsite for Vagrant boxes

httpopscodegithubiobento Vagrant boxes optimized for Chef

You can create your own box using- Packer (httppackerio)- Packer templates for Chef optimized boxes can be found

httpsgithubcomopscodebento

Synced FolderTo enable Vagrant to sync files at your Host and Guest machine

By default mapped directory vagrant

Permissions all files in synced folder are 0777

Vagrant PluginsVagrant is extremely pluggable

You can addcostomize almost everything in Vagrant (such as add VMWare AWS or Docker providers) Chef or Puppet provisioning etc

Vagrant has tons of plugins Official hosted here httpsgithubcommitchellhvagranttreemasterplugins

Dog Food API for Vagrant plugins httpenwikipediaorgwikiEating_your_own_dog_food

Most useful Plugins- vagrant-omnibus Chef for Vagrant VMs- vagrant-cachier Cache for packages (can be reused across

VMs)- vagrant-berkshelf Enable Chef cookbook dependency

mechanism

Vagrant plugins commandCLI to manage vagrant plugins

Will be installed in homevagrantdgemsShell

$ vagrant plugin install

$ vagrant plugin list

$ vagrant plugin uninstall

$ vagrant plugin update

Install vagrant pluginList of installed pluginsErase plugin

Check plugin and update with newer version

Activity 1Run a vagrant box

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 7: DevOps Hackathon - Session 1: Vagrant

Command Line InterfaceVagrant basic operating model through CLI vagrant command

Running any vagrant subcommand with --help or ndashh prints context help

$ vagrant init

$ vagrant up

$ vagrant halt

$ vagrant reload

$ vagrant provision

$ vagrant destroy

$ vagrant ssh

$ vagrant ssh-config

Create initial Vagrant configuratoinStart or create VM if not existsPower down VM

Restart VM (useful when you change config)

Run Chef or Puppet scripts

Destroy VM as it never existed

Connect to VM if it is running

Prints SSH configuration

Command Line Interface

shell$ vagrant box list

$ vagrant box add

$ vagrant box remove

$ vagrant box repackage

$ vagrant box outdated

$ vagrant box update

List all vagrant environments on your PCAdd basebox record to vagrant registryRemove basebox (doesnrsquot terminate VM)

Make a snapshot of your VM

Deprecates the VM

Checks and updates a VM if it is out-dated

Additional commands to manage your vagrant environments

VagrantfileAll VM configuration stored in Ruby DSL file This file can be placed in git

When you run vagrant up Vagrant will check following directories

Vagrantfile homemitchellhprojectsfooVagrantfile homemitchellhprojectsVagrantfile homemitchellhVagrantfile homeVagrantfile Vagrantfile

VAGRANT_CWD to change directory where Vagrant is looking for configuration

Boxes

VagrantfileVagrantconfigure 2 do |config|

configvmbox = ldquomy-vm

configvmbox_url = ldquobox-url

end

Minimal Vagrantfile looks like this

Vagrant file contains API versioning

Vagrantfile (cont)Vagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

How many machines will run this file

Modifying scriptsconfigvm ndash to mange VM parameters

Vagrantfileconfigvmbox

configvmcheck_update

configvmbox_url

configvmbox_version

configvmboxhostname

configvmprovider

cofnigvmsynced_folder

Name to be associated with boxBy default true Can disable update checksURL of the VM to downloadVersion of the basebox file

Hostname of the VM

By default VirtualBox Can be other

By default current host dir mounted as Vagrant Can map additional directory inside VM

Modifying scriptsconfigssh ndash to customize SSH behavior

Vagrantfileconfigsshusername

configsshpassword

configsshprivate_key_path

configsshinsert_key

configsshshell

By default vagrantNo pass by default

Path to your SSH key By default homevagrantdinsecure_private_key

By default true Can disable to use passShell to open when ssh By default bash -l

BoxesTo create a VM Vagrant needs a basebox file which is typically Just Enough Operating System

Baseboxes can be downloaded from Community websiteswwwvagrantboxes Offsite for Vagrant boxes

httpopscodegithubiobento Vagrant boxes optimized for Chef

You can create your own box using- Packer (httppackerio)- Packer templates for Chef optimized boxes can be found

httpsgithubcomopscodebento

Synced FolderTo enable Vagrant to sync files at your Host and Guest machine

By default mapped directory vagrant

Permissions all files in synced folder are 0777

Vagrant PluginsVagrant is extremely pluggable

You can addcostomize almost everything in Vagrant (such as add VMWare AWS or Docker providers) Chef or Puppet provisioning etc

Vagrant has tons of plugins Official hosted here httpsgithubcommitchellhvagranttreemasterplugins

Dog Food API for Vagrant plugins httpenwikipediaorgwikiEating_your_own_dog_food

Most useful Plugins- vagrant-omnibus Chef for Vagrant VMs- vagrant-cachier Cache for packages (can be reused across

VMs)- vagrant-berkshelf Enable Chef cookbook dependency

mechanism

Vagrant plugins commandCLI to manage vagrant plugins

Will be installed in homevagrantdgemsShell

$ vagrant plugin install

$ vagrant plugin list

$ vagrant plugin uninstall

$ vagrant plugin update

Install vagrant pluginList of installed pluginsErase plugin

Check plugin and update with newer version

Activity 1Run a vagrant box

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 8: DevOps Hackathon - Session 1: Vagrant

Command Line Interface

shell$ vagrant box list

$ vagrant box add

$ vagrant box remove

$ vagrant box repackage

$ vagrant box outdated

$ vagrant box update

List all vagrant environments on your PCAdd basebox record to vagrant registryRemove basebox (doesnrsquot terminate VM)

Make a snapshot of your VM

Deprecates the VM

Checks and updates a VM if it is out-dated

Additional commands to manage your vagrant environments

VagrantfileAll VM configuration stored in Ruby DSL file This file can be placed in git

When you run vagrant up Vagrant will check following directories

Vagrantfile homemitchellhprojectsfooVagrantfile homemitchellhprojectsVagrantfile homemitchellhVagrantfile homeVagrantfile Vagrantfile

VAGRANT_CWD to change directory where Vagrant is looking for configuration

Boxes

VagrantfileVagrantconfigure 2 do |config|

configvmbox = ldquomy-vm

configvmbox_url = ldquobox-url

end

Minimal Vagrantfile looks like this

Vagrant file contains API versioning

Vagrantfile (cont)Vagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

How many machines will run this file

Modifying scriptsconfigvm ndash to mange VM parameters

Vagrantfileconfigvmbox

configvmcheck_update

configvmbox_url

configvmbox_version

configvmboxhostname

configvmprovider

cofnigvmsynced_folder

Name to be associated with boxBy default true Can disable update checksURL of the VM to downloadVersion of the basebox file

Hostname of the VM

By default VirtualBox Can be other

By default current host dir mounted as Vagrant Can map additional directory inside VM

Modifying scriptsconfigssh ndash to customize SSH behavior

Vagrantfileconfigsshusername

configsshpassword

configsshprivate_key_path

configsshinsert_key

configsshshell

By default vagrantNo pass by default

Path to your SSH key By default homevagrantdinsecure_private_key

By default true Can disable to use passShell to open when ssh By default bash -l

BoxesTo create a VM Vagrant needs a basebox file which is typically Just Enough Operating System

Baseboxes can be downloaded from Community websiteswwwvagrantboxes Offsite for Vagrant boxes

httpopscodegithubiobento Vagrant boxes optimized for Chef

You can create your own box using- Packer (httppackerio)- Packer templates for Chef optimized boxes can be found

httpsgithubcomopscodebento

Synced FolderTo enable Vagrant to sync files at your Host and Guest machine

By default mapped directory vagrant

Permissions all files in synced folder are 0777

Vagrant PluginsVagrant is extremely pluggable

You can addcostomize almost everything in Vagrant (such as add VMWare AWS or Docker providers) Chef or Puppet provisioning etc

Vagrant has tons of plugins Official hosted here httpsgithubcommitchellhvagranttreemasterplugins

Dog Food API for Vagrant plugins httpenwikipediaorgwikiEating_your_own_dog_food

Most useful Plugins- vagrant-omnibus Chef for Vagrant VMs- vagrant-cachier Cache for packages (can be reused across

VMs)- vagrant-berkshelf Enable Chef cookbook dependency

mechanism

Vagrant plugins commandCLI to manage vagrant plugins

Will be installed in homevagrantdgemsShell

$ vagrant plugin install

$ vagrant plugin list

$ vagrant plugin uninstall

$ vagrant plugin update

Install vagrant pluginList of installed pluginsErase plugin

Check plugin and update with newer version

Activity 1Run a vagrant box

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 9: DevOps Hackathon - Session 1: Vagrant

VagrantfileAll VM configuration stored in Ruby DSL file This file can be placed in git

When you run vagrant up Vagrant will check following directories

Vagrantfile homemitchellhprojectsfooVagrantfile homemitchellhprojectsVagrantfile homemitchellhVagrantfile homeVagrantfile Vagrantfile

VAGRANT_CWD to change directory where Vagrant is looking for configuration

Boxes

VagrantfileVagrantconfigure 2 do |config|

configvmbox = ldquomy-vm

configvmbox_url = ldquobox-url

end

Minimal Vagrantfile looks like this

Vagrant file contains API versioning

Vagrantfile (cont)Vagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

How many machines will run this file

Modifying scriptsconfigvm ndash to mange VM parameters

Vagrantfileconfigvmbox

configvmcheck_update

configvmbox_url

configvmbox_version

configvmboxhostname

configvmprovider

cofnigvmsynced_folder

Name to be associated with boxBy default true Can disable update checksURL of the VM to downloadVersion of the basebox file

Hostname of the VM

By default VirtualBox Can be other

By default current host dir mounted as Vagrant Can map additional directory inside VM

Modifying scriptsconfigssh ndash to customize SSH behavior

Vagrantfileconfigsshusername

configsshpassword

configsshprivate_key_path

configsshinsert_key

configsshshell

By default vagrantNo pass by default

Path to your SSH key By default homevagrantdinsecure_private_key

By default true Can disable to use passShell to open when ssh By default bash -l

BoxesTo create a VM Vagrant needs a basebox file which is typically Just Enough Operating System

Baseboxes can be downloaded from Community websiteswwwvagrantboxes Offsite for Vagrant boxes

httpopscodegithubiobento Vagrant boxes optimized for Chef

You can create your own box using- Packer (httppackerio)- Packer templates for Chef optimized boxes can be found

httpsgithubcomopscodebento

Synced FolderTo enable Vagrant to sync files at your Host and Guest machine

By default mapped directory vagrant

Permissions all files in synced folder are 0777

Vagrant PluginsVagrant is extremely pluggable

You can addcostomize almost everything in Vagrant (such as add VMWare AWS or Docker providers) Chef or Puppet provisioning etc

Vagrant has tons of plugins Official hosted here httpsgithubcommitchellhvagranttreemasterplugins

Dog Food API for Vagrant plugins httpenwikipediaorgwikiEating_your_own_dog_food

Most useful Plugins- vagrant-omnibus Chef for Vagrant VMs- vagrant-cachier Cache for packages (can be reused across

VMs)- vagrant-berkshelf Enable Chef cookbook dependency

mechanism

Vagrant plugins commandCLI to manage vagrant plugins

Will be installed in homevagrantdgemsShell

$ vagrant plugin install

$ vagrant plugin list

$ vagrant plugin uninstall

$ vagrant plugin update

Install vagrant pluginList of installed pluginsErase plugin

Check plugin and update with newer version

Activity 1Run a vagrant box

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 10: DevOps Hackathon - Session 1: Vagrant

Boxes

VagrantfileVagrantconfigure 2 do |config|

configvmbox = ldquomy-vm

configvmbox_url = ldquobox-url

end

Minimal Vagrantfile looks like this

Vagrant file contains API versioning

Vagrantfile (cont)Vagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

How many machines will run this file

Modifying scriptsconfigvm ndash to mange VM parameters

Vagrantfileconfigvmbox

configvmcheck_update

configvmbox_url

configvmbox_version

configvmboxhostname

configvmprovider

cofnigvmsynced_folder

Name to be associated with boxBy default true Can disable update checksURL of the VM to downloadVersion of the basebox file

Hostname of the VM

By default VirtualBox Can be other

By default current host dir mounted as Vagrant Can map additional directory inside VM

Modifying scriptsconfigssh ndash to customize SSH behavior

Vagrantfileconfigsshusername

configsshpassword

configsshprivate_key_path

configsshinsert_key

configsshshell

By default vagrantNo pass by default

Path to your SSH key By default homevagrantdinsecure_private_key

By default true Can disable to use passShell to open when ssh By default bash -l

BoxesTo create a VM Vagrant needs a basebox file which is typically Just Enough Operating System

Baseboxes can be downloaded from Community websiteswwwvagrantboxes Offsite for Vagrant boxes

httpopscodegithubiobento Vagrant boxes optimized for Chef

You can create your own box using- Packer (httppackerio)- Packer templates for Chef optimized boxes can be found

httpsgithubcomopscodebento

Synced FolderTo enable Vagrant to sync files at your Host and Guest machine

By default mapped directory vagrant

Permissions all files in synced folder are 0777

Vagrant PluginsVagrant is extremely pluggable

You can addcostomize almost everything in Vagrant (such as add VMWare AWS or Docker providers) Chef or Puppet provisioning etc

Vagrant has tons of plugins Official hosted here httpsgithubcommitchellhvagranttreemasterplugins

Dog Food API for Vagrant plugins httpenwikipediaorgwikiEating_your_own_dog_food

Most useful Plugins- vagrant-omnibus Chef for Vagrant VMs- vagrant-cachier Cache for packages (can be reused across

VMs)- vagrant-berkshelf Enable Chef cookbook dependency

mechanism

Vagrant plugins commandCLI to manage vagrant plugins

Will be installed in homevagrantdgemsShell

$ vagrant plugin install

$ vagrant plugin list

$ vagrant plugin uninstall

$ vagrant plugin update

Install vagrant pluginList of installed pluginsErase plugin

Check plugin and update with newer version

Activity 1Run a vagrant box

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 11: DevOps Hackathon - Session 1: Vagrant

Vagrantfile (cont)Vagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

How many machines will run this file

Modifying scriptsconfigvm ndash to mange VM parameters

Vagrantfileconfigvmbox

configvmcheck_update

configvmbox_url

configvmbox_version

configvmboxhostname

configvmprovider

cofnigvmsynced_folder

Name to be associated with boxBy default true Can disable update checksURL of the VM to downloadVersion of the basebox file

Hostname of the VM

By default VirtualBox Can be other

By default current host dir mounted as Vagrant Can map additional directory inside VM

Modifying scriptsconfigssh ndash to customize SSH behavior

Vagrantfileconfigsshusername

configsshpassword

configsshprivate_key_path

configsshinsert_key

configsshshell

By default vagrantNo pass by default

Path to your SSH key By default homevagrantdinsecure_private_key

By default true Can disable to use passShell to open when ssh By default bash -l

BoxesTo create a VM Vagrant needs a basebox file which is typically Just Enough Operating System

Baseboxes can be downloaded from Community websiteswwwvagrantboxes Offsite for Vagrant boxes

httpopscodegithubiobento Vagrant boxes optimized for Chef

You can create your own box using- Packer (httppackerio)- Packer templates for Chef optimized boxes can be found

httpsgithubcomopscodebento

Synced FolderTo enable Vagrant to sync files at your Host and Guest machine

By default mapped directory vagrant

Permissions all files in synced folder are 0777

Vagrant PluginsVagrant is extremely pluggable

You can addcostomize almost everything in Vagrant (such as add VMWare AWS or Docker providers) Chef or Puppet provisioning etc

Vagrant has tons of plugins Official hosted here httpsgithubcommitchellhvagranttreemasterplugins

Dog Food API for Vagrant plugins httpenwikipediaorgwikiEating_your_own_dog_food

Most useful Plugins- vagrant-omnibus Chef for Vagrant VMs- vagrant-cachier Cache for packages (can be reused across

VMs)- vagrant-berkshelf Enable Chef cookbook dependency

mechanism

Vagrant plugins commandCLI to manage vagrant plugins

Will be installed in homevagrantdgemsShell

$ vagrant plugin install

$ vagrant plugin list

$ vagrant plugin uninstall

$ vagrant plugin update

Install vagrant pluginList of installed pluginsErase plugin

Check plugin and update with newer version

Activity 1Run a vagrant box

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 12: DevOps Hackathon - Session 1: Vagrant

Modifying scriptsconfigvm ndash to mange VM parameters

Vagrantfileconfigvmbox

configvmcheck_update

configvmbox_url

configvmbox_version

configvmboxhostname

configvmprovider

cofnigvmsynced_folder

Name to be associated with boxBy default true Can disable update checksURL of the VM to downloadVersion of the basebox file

Hostname of the VM

By default VirtualBox Can be other

By default current host dir mounted as Vagrant Can map additional directory inside VM

Modifying scriptsconfigssh ndash to customize SSH behavior

Vagrantfileconfigsshusername

configsshpassword

configsshprivate_key_path

configsshinsert_key

configsshshell

By default vagrantNo pass by default

Path to your SSH key By default homevagrantdinsecure_private_key

By default true Can disable to use passShell to open when ssh By default bash -l

BoxesTo create a VM Vagrant needs a basebox file which is typically Just Enough Operating System

Baseboxes can be downloaded from Community websiteswwwvagrantboxes Offsite for Vagrant boxes

httpopscodegithubiobento Vagrant boxes optimized for Chef

You can create your own box using- Packer (httppackerio)- Packer templates for Chef optimized boxes can be found

httpsgithubcomopscodebento

Synced FolderTo enable Vagrant to sync files at your Host and Guest machine

By default mapped directory vagrant

Permissions all files in synced folder are 0777

Vagrant PluginsVagrant is extremely pluggable

You can addcostomize almost everything in Vagrant (such as add VMWare AWS or Docker providers) Chef or Puppet provisioning etc

Vagrant has tons of plugins Official hosted here httpsgithubcommitchellhvagranttreemasterplugins

Dog Food API for Vagrant plugins httpenwikipediaorgwikiEating_your_own_dog_food

Most useful Plugins- vagrant-omnibus Chef for Vagrant VMs- vagrant-cachier Cache for packages (can be reused across

VMs)- vagrant-berkshelf Enable Chef cookbook dependency

mechanism

Vagrant plugins commandCLI to manage vagrant plugins

Will be installed in homevagrantdgemsShell

$ vagrant plugin install

$ vagrant plugin list

$ vagrant plugin uninstall

$ vagrant plugin update

Install vagrant pluginList of installed pluginsErase plugin

Check plugin and update with newer version

Activity 1Run a vagrant box

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 13: DevOps Hackathon - Session 1: Vagrant

Modifying scriptsconfigssh ndash to customize SSH behavior

Vagrantfileconfigsshusername

configsshpassword

configsshprivate_key_path

configsshinsert_key

configsshshell

By default vagrantNo pass by default

Path to your SSH key By default homevagrantdinsecure_private_key

By default true Can disable to use passShell to open when ssh By default bash -l

BoxesTo create a VM Vagrant needs a basebox file which is typically Just Enough Operating System

Baseboxes can be downloaded from Community websiteswwwvagrantboxes Offsite for Vagrant boxes

httpopscodegithubiobento Vagrant boxes optimized for Chef

You can create your own box using- Packer (httppackerio)- Packer templates for Chef optimized boxes can be found

httpsgithubcomopscodebento

Synced FolderTo enable Vagrant to sync files at your Host and Guest machine

By default mapped directory vagrant

Permissions all files in synced folder are 0777

Vagrant PluginsVagrant is extremely pluggable

You can addcostomize almost everything in Vagrant (such as add VMWare AWS or Docker providers) Chef or Puppet provisioning etc

Vagrant has tons of plugins Official hosted here httpsgithubcommitchellhvagranttreemasterplugins

Dog Food API for Vagrant plugins httpenwikipediaorgwikiEating_your_own_dog_food

Most useful Plugins- vagrant-omnibus Chef for Vagrant VMs- vagrant-cachier Cache for packages (can be reused across

VMs)- vagrant-berkshelf Enable Chef cookbook dependency

mechanism

Vagrant plugins commandCLI to manage vagrant plugins

Will be installed in homevagrantdgemsShell

$ vagrant plugin install

$ vagrant plugin list

$ vagrant plugin uninstall

$ vagrant plugin update

Install vagrant pluginList of installed pluginsErase plugin

Check plugin and update with newer version

Activity 1Run a vagrant box

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 14: DevOps Hackathon - Session 1: Vagrant

BoxesTo create a VM Vagrant needs a basebox file which is typically Just Enough Operating System

Baseboxes can be downloaded from Community websiteswwwvagrantboxes Offsite for Vagrant boxes

httpopscodegithubiobento Vagrant boxes optimized for Chef

You can create your own box using- Packer (httppackerio)- Packer templates for Chef optimized boxes can be found

httpsgithubcomopscodebento

Synced FolderTo enable Vagrant to sync files at your Host and Guest machine

By default mapped directory vagrant

Permissions all files in synced folder are 0777

Vagrant PluginsVagrant is extremely pluggable

You can addcostomize almost everything in Vagrant (such as add VMWare AWS or Docker providers) Chef or Puppet provisioning etc

Vagrant has tons of plugins Official hosted here httpsgithubcommitchellhvagranttreemasterplugins

Dog Food API for Vagrant plugins httpenwikipediaorgwikiEating_your_own_dog_food

Most useful Plugins- vagrant-omnibus Chef for Vagrant VMs- vagrant-cachier Cache for packages (can be reused across

VMs)- vagrant-berkshelf Enable Chef cookbook dependency

mechanism

Vagrant plugins commandCLI to manage vagrant plugins

Will be installed in homevagrantdgemsShell

$ vagrant plugin install

$ vagrant plugin list

$ vagrant plugin uninstall

$ vagrant plugin update

Install vagrant pluginList of installed pluginsErase plugin

Check plugin and update with newer version

Activity 1Run a vagrant box

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 15: DevOps Hackathon - Session 1: Vagrant

Synced FolderTo enable Vagrant to sync files at your Host and Guest machine

By default mapped directory vagrant

Permissions all files in synced folder are 0777

Vagrant PluginsVagrant is extremely pluggable

You can addcostomize almost everything in Vagrant (such as add VMWare AWS or Docker providers) Chef or Puppet provisioning etc

Vagrant has tons of plugins Official hosted here httpsgithubcommitchellhvagranttreemasterplugins

Dog Food API for Vagrant plugins httpenwikipediaorgwikiEating_your_own_dog_food

Most useful Plugins- vagrant-omnibus Chef for Vagrant VMs- vagrant-cachier Cache for packages (can be reused across

VMs)- vagrant-berkshelf Enable Chef cookbook dependency

mechanism

Vagrant plugins commandCLI to manage vagrant plugins

Will be installed in homevagrantdgemsShell

$ vagrant plugin install

$ vagrant plugin list

$ vagrant plugin uninstall

$ vagrant plugin update

Install vagrant pluginList of installed pluginsErase plugin

Check plugin and update with newer version

Activity 1Run a vagrant box

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 16: DevOps Hackathon - Session 1: Vagrant

Vagrant PluginsVagrant is extremely pluggable

You can addcostomize almost everything in Vagrant (such as add VMWare AWS or Docker providers) Chef or Puppet provisioning etc

Vagrant has tons of plugins Official hosted here httpsgithubcommitchellhvagranttreemasterplugins

Dog Food API for Vagrant plugins httpenwikipediaorgwikiEating_your_own_dog_food

Most useful Plugins- vagrant-omnibus Chef for Vagrant VMs- vagrant-cachier Cache for packages (can be reused across

VMs)- vagrant-berkshelf Enable Chef cookbook dependency

mechanism

Vagrant plugins commandCLI to manage vagrant plugins

Will be installed in homevagrantdgemsShell

$ vagrant plugin install

$ vagrant plugin list

$ vagrant plugin uninstall

$ vagrant plugin update

Install vagrant pluginList of installed pluginsErase plugin

Check plugin and update with newer version

Activity 1Run a vagrant box

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 17: DevOps Hackathon - Session 1: Vagrant

Vagrant plugins commandCLI to manage vagrant plugins

Will be installed in homevagrantdgemsShell

$ vagrant plugin install

$ vagrant plugin list

$ vagrant plugin uninstall

$ vagrant plugin update

Install vagrant pluginList of installed pluginsErase plugin

Check plugin and update with newer version

Activity 1Run a vagrant box

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 18: DevOps Hackathon - Session 1: Vagrant

Activity 1Run a vagrant box

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 19: DevOps Hackathon - Session 1: Vagrant

Activity 1Go to activity1 directory

1 Create a vagrant box file$ vagrant init vagrant-hackaton httpopscode-vm-bentos3amazonawscomvagrantvmwareopscode_ubuntu-1404_chef-provisionerlessbox

2 Run command

This will create a Vagrant configuration which is pointed to URL This is a good manner to specify Valid URL so vagrant config can be repeatable out of box

$ vagrant up

This will start download image from Internet Please spare our bandwidth and terminate this process (CTRL+C) We will add image from our local disk

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 20: DevOps Hackathon - Session 1: Vagrant

Activity 13 Check if nothing installed$ vagrant box list

5 Spin up VM

Vagrant should return no images Otherwise we might overwrite one with this activity Or you might want to change name of VM by modifying Vagrantfile

4 Add box manually with link to local file$ vagrant box add vagrant-hackaton PATH-TO-BOXopscode_ubuntu-1404_chef-provisionerlessbox

$ vagrant up

6 Connect via SSH$ vagrant ssh

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 21: DevOps Hackathon - Session 1: Vagrant

Activity 17 Type command

$ vagrant destroy

8 Destroy VM

in VM$ uptime$ exit

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 22: DevOps Hackathon - Session 1: Vagrant

Activity 2Customize VM attributes

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 23: DevOps Hackathon - Session 1: Vagrant

Activity 2Go to activity2 directory

1 Run command $ vagrant up

This will bring VM to life Vagrant will reuse basebox from local file because activity2 VM has same name as VM from activty1

2 In the VM run command

You should get some HTML text on console Before exiting SSH sesion

in VM$ sudo apt-get install ndashy apache2 curl$ httplocalhost$ exit

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 24: DevOps Hackathon - Session 1: Vagrant

Activity 23 Modify Vagrantfile

This will instruct Vagrant to use cache on your Host machine all software installed inside VM (vagrant requires plugin vagrant-cachier)

4 Modify Vagrantfile as per instructionsVagrantfile TODO2configvmnetwork forwarded_port guest XXXXX host YYYYY

Vagrantfile TODO1configcacheauto_detect = true

Vagrantfile TODO3configvmsynced_folder webapp varwww

5 Modify Vagrantfile as per instructions

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 25: DevOps Hackathon - Session 1: Vagrant

Activity 25 after Vagrantfile changes we need to raload VM$ vagrant reload

6 With your browser open httplocalhost80801 You will get something like this (on the right)

This is allright We need to create a HTML

7 Create file webappindexhtmlwebappindexhtmllthtmlgt ltheadgtlttitlegtHello Worldlttitlegtltheadgt ltbodygtlth1gtHello Vagrantlth1gtltbodylthtmlgt

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 26: DevOps Hackathon - Session 1: Vagrant

Activity 2No needs to reload VM (directory will be synced automagically )

8 Refresh your browser at httplocalhost80801 You will get something like this (on the right)

7 Destroy VM$ vagrant destroy

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 27: DevOps Hackathon - Session 1: Vagrant

Activity 3Provision DB Server

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 28: DevOps Hackathon - Session 1: Vagrant

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrant will fail withVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 You need to install additional plugins$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 29: DevOps Hackathon - Session 1: Vagrant

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 30: DevOps Hackathon - Session 1: Vagrant

Activity 3Go to activity3 directory

1 Run command $ vagrant up

Vagrantfile has extra configuration that says it will use Chef (Omnibus packaged) and Berkshelf to download cookbooks But it doesnrsquot have plugins and it will failVagrant Unknown configuration section berkshelf Unknown configuration section omnibus

2 Check if plugins installed and install plugins$ vagrant plugin list$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-omnibus

$ vagrant up

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 31: DevOps Hackathon - Session 1: Vagrant

Retrospective

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 32: DevOps Hackathon - Session 1: Vagrant

How many VMs will this file runVagrantfile

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm

configvmbox_url = ldquobox-urlldquo

(13)each do |i| configvmdefine slave-i do |slave| slavevmprovision shell inline echo hello from slave i end endend

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 33: DevOps Hackathon - Session 1: Vagrant

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 34: DevOps Hackathon - Session 1: Vagrant

Synced folder tricks

Vagrantfilerequire rbconfigis_windows = (RbConfigCONFIG[host_os] =~ mswin|mingw|cygwin)

Vagrantconfigure 2 do |config| configvmbox = ldquomy-vm configvmbox_url = ldquobox-urlldquo

configvmsynced_folder webapp varwwwhtml nfs is_windowsend

Synced folder in windows synchronizes in one direction To enable it to synchronize in both directions we need to say that host system is Windows by setting parameter nfs to true

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 35: DevOps Hackathon - Session 1: Vagrant

Synced folder tricksIf Windows host machine you cannot create symlinks in synced directory

However there is a workaround

1 Add vm customization parameter to VagrantfileVagrantfileconfigvmcustomize [setextradata id VBoxInternal2SharedFoldersEnableSymlinksCreatev-root 1] if is_windows

2 Run vagrant up as user Administrator

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 36: DevOps Hackathon - Session 1: Vagrant

Shell$ git clone httpsgithubcomopscodebentogit$ cd bentopackerbentopacker $ packer build ubuntu-1310-amd64json

Creating VM from scratch

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params
Page 37: DevOps Hackathon - Session 1: Vagrant

Shellbentopacker $ packer build -only=virtualbox -var-file=variablesjson ubuntu-1310-amd64json

Packer with extra params

variablesjson chef_version latest mirror buildsiso

  • Slide 1
  • Vagrant
  • Vagrant (2)
  • Vagrant (3)
  • Installing Vagrant
  • Vagrant Components
  • Command Line Interface
  • Command Line Interface (2)
  • Vagrantfile
  • Boxes
  • Vagrantfile (cont)
  • Modifying scripts
  • Modifying scripts (2)
  • Boxes (2)
  • Synced Folder
  • Vagrant Plugins
  • Vagrant plugins command
  • Slide 18
  • Activity 1
  • Activity 1 (2)
  • Activity 1 (3)
  • Slide 22
  • Activity 2
  • Activity 2 (2)
  • Activity 2 (3)
  • Activity 2 (4)
  • Slide 27
  • Activity 3
  • Activity 3 (2)
  • Activity 3 (3)
  • Slide 31
  • How many VMs will this file run
  • Synced folder tricks
  • Synced folder tricks (2)
  • Synced folder tricks (3)
  • Creating VM from scratch
  • Packer with extra params