Basic example
Create a Vagrantfile
[~]$ mkdir foss_rocks
[~]$ cd foss_rocks
[~/foss_rocks]$ vagrant init -m chef/fedora-20
[~/foss_rocks]$ ls
Vagrantfile
BASIC EXAMPLE
It's so simple!
[~/foss_rocks]$ cat Vagrantfile
Vagrant.configure(2) do |config|
config.vm.box = "chef/fedora-20"
end
Basic Example
Boot the VM
[~/foss_rocks]$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'chef/fedora-20' is up to date...
==> default: Preparing network interfaces based on configuration...
==> default: Booting VM...
==> default: Machine booted and ready!
==> default: Mounting shared folders...
default: /vagrant => /home/daniel/foss_rocks
Basic Example
Connect to the VM
[~/foss_rocks]$ vagrant ssh
Last login: Fri Dec 20 18:02:34 2013 from 10.0.2.2
[vagrant@localhost ~]$
Basic Example
It works!
[vagrant@localhost ~]$ ping 8.8.8.8 -c 1
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=63 time=13.7 ms
[vagrant@localhost ~]$ cat /etc/issue
Fedora release 20 (Heisenbug)
BASIC EXAMPLE
Vagrantfile dir is hard linked to /vagrant (default)
[vagrant@localhost ~]$ ls /vagrant/
Vagrantfile
PUPPET PROVISIONER
Add Puppet provisioning to basic example
Vagrant.configure(2) do |config|
config.vm.box = "chef/fedora-20"
# Install Puppet
config.vm.provision "shell", inline: "yum install -y puppet"
# Install OpenDaylight using its Puppet module
config.vm.provision "puppet" do |puppet|
# Mostly using default settings
# The module path tells Puppet where to find required modules
puppet.module_path = ["modules"]
end
end
PUPPET PROVISIONER
Note the "Convention over Configuration"
config.vm.provision "puppet" do |puppet|
# Mostly using default settings
# The module path tells Puppet where to find required modules
puppet.module_path = ["modules"]
end
PUPPET PROVISIONER
Convention for file layout
[~/foss_rocks]$ tree
.
├── manifests
│ └── default.pp
└── Vagrantfile
PUPPET PROVISIONER
The Puppet manifest is trivial
[~/foss_rocks]$ cat manifests/default.pp
include ::opendaylight
PUPPET PROVISIONER
Puppet-specific stuff to manage modules
[~/foss_rocks]$ tree
.
├── Gemfile
├── manifests
│ └── default.pp
├── Puppetfile
└── Vagrantfile
PUPPET PROVISIONER
Gemfile is for sharing gem config via Bundler
[~/foss_rocks]$ cat Gemfile
source "https://rubygems.org"
gem 'puppet'
gem 'librarian-puppet' # Used for managing Puppet mods
PUPPET PROVISIONER
Puppetfile describes how to find ODL mod
(only needed b/c it's not on the Forge)
[~/foss_rocks]$ cat Puppetfile
#!/usr/bin/env ruby
forge "https://forgeapi.puppetlabs.com"
mod 'dfarrell07-opendaylight',
:git => 'git://github.com/dfarrell07/puppet-opendaylight.git'
PUPPET PROVISIONER
Install all required gems
[~/foss_rocks]$ bundle install
[snip]
Your bundle is complete!
PUPPET PROVISIONER
Install OpenDaylight Puppet module
[~/foss_rocks]$ ls
Gemfile manifests Puppetfile Vagrantfile
[~/foss_rocks]$ librarian-puppet install
[~/foss_rocks]$ tree -L 2
.
├── Gemfile
├── manifests
│ └── default.pp
├── modules
│ ├── opendaylight
│ └── stdlib
├── Puppetfile
├── Puppetfile.lock
└── Vagrantfile
PUPPET PROVISIONER
For a change, let's destroy the VM
[~/foss_rocks]$ vagrant destroy -f
==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...
==> default: Running cleanup tasks for 'shell' provisioner...
[~/foss_rocks]$ vagrant status
Current machine states:
default not created (virtualbox)
PUPPET PROVISIONER
Now rebuild it, using Puppet to install ODL
[~/foss_rocks]$ vagrant up
==> default: Running provisioner: shell...
==> default: Running provisioner: puppet...
==> default: Running Puppet with default.pp...
==> default: Notice: Finished catalog run in 59.59 seconds
PUPPET PROVISIONER
Connect and show that ODL is working
[~/foss_rocks]$ vagrant ssh
Last login: Fri Dec 20 18:02:34 2013 from 10.0.2.2
[vagrant@localhost ~]$ sudo systemctl is-active opendaylight
active
Multi-machine
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "cent7_puppet" do |cent7_puppet|
# Configure CentOS 7 box using Puppet
to install ODL
end
config.vm.define "fed20_puppet" do |fed20_puppet|
# Configure Fedora 20 box using Puppet
to install ODL
end
config.vm.define "fed20_rpm" do |fed20_rpm|
# Configure Fedora 20 box using RPM to install ODL
end
config.vm.define "cent7_rpm" do |cent7_rpm|
# Configure CentOS 7 box using RPM to install ODL
end
MULTI-MACHINE
config.vm.define "cent7_puppet" do |cent7_puppet|
# Build Vagrant box based on CentOS 7
cent7_puppet.vm.box = "chef/centos-7.0"
# Add Puppet repo and install Puppet
cent7_puppet.vm.provision "shell", inline: "rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm"
cent7_puppet.vm.provision "shell", inline: "yum install -y puppet"
# Snip: Puppet provisioning step
end
config.vm.define "fed20_puppet" do |fed20_puppet|
# Build Vagrant box based on Fedora 20
fed20_puppet.vm.box = "chef/fedora-20"
# Install Puppet
fed20_puppet.vm.provision "shell", inline: "yum install -y puppet"
# Snip: Puppet provisioning step
end
MULTI-MACHINE
[~/vagrant_opendaylight]$ vagrant status
Current machine states:
cent7_puppet not created (virtualbox)
fed20_puppet poweroff (virtualbox)