SlideShare a Scribd company logo
@coldfumonkeh
Matt Gifford
WINNING with
VAGRANT, PUPPET
and CHEF
ITB2015 - Winning with Vagrant, Puppet and Chef
ITB2015 - Winning with Vagrant, Puppet and Chef
Create and configure
lightweight, reproducible, and
portable development
environments.
ITB2015 - Winning with Vagrant, Puppet and Chef
ITB2015 - Winning with Vagrant, Puppet and Chef
QUESTION
ITB2015 - Winning with Vagrant, Puppet and Chef
Environment per project
Dev ~= Test ~= Staging ~= Production
Easy to define & transport
Easy to tear down
Provisionable
Versionable
Shared across the team
➜ ~
Usage: vagrant [options] <command> [<args>]
-v, --version Print the version and exit.
-h, --help Print this help.
vagrant
Common commands:
box manages boxes: installation, removal, etc.
connect connect to a remotely shared Vagrant environment
destroy stops and deletes all traces of the vagrant machine
global-status outputs status Vagrant environments for this user
halt stops the vagrant machine
help shows the help for a subcommand
init initializes a new Vagrant environment by creating a Vagrantfile
login log in to Vagrant Cloud
package packages a running vagrant environment into a box
plugin manages plugins: install, uninstall, update, etc.
provision provisions the vagrant machine
rdp connects to machine via RDP
reload restarts vagrant machine, loads new Vagrantfile configuration
resume resume a suspended vagrant machine
share share your Vagrant environment with anyone in the world
ssh connects to machine via SSH
ssh-config outputs OpenSSH valid configuration to connect to the machine
status outputs status of the vagrant machine
suspend suspends the machine
up starts and provisions the vagrant environment
version prints current and latest Vagrant version
For help on any individual command run `vagrant COMMAND -h`
Additional subcommands are available, but are either more
advanced or not commonly used.
To see all subcommands, run the command
`vagrant list-commands`.
Generating a
VagrantïŹle
Select base box
Choose virtualization provider
Configure VM parameters
Configure networking
Tweak SSH settings
Mount local folders
Provision machine
➜ ~
Usage: vagrant init [options] [name [url]]
Options:
-f, --force Overwrite existing Vagrantfile
-m, --minimal Create minimal Vagrantfile (no help comments)
--output FILE Output path for the box. '-' for stdout
-h, --help Print this help
vagrant init -h
➜ ~ vagrant init
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
15
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg|
conïŹg.vm.box = "base"
end
➜ ~ vagrant init precise32 http://files.vagrantup.com/precise32.box
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
17
VagrantïŹle
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg|
conïŹg.vm.box = "precise32"
conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box"
end
Boxes
http://vagrantbox.es
https://atlas.hashicorp.com/boxes/search
https://github.com/jedi4ever/veewee
https://packer.io
ITB2015 - Winning with Vagrant, Puppet and Chef
Box Management
➜ ~
Usage: vagrant box <subcommand> [<args>]
Available subcommands:
add
list
outdated
remove
repackage
update
vagrant box
➜ ~
==> box: Adding box 'precise32' (v0) for provider: virtualbox
box: Downloading: http://files.vagrantup.com/precise32.box
box: Progress: 38% (Rate: 615k/s, Estimated time remaining: 0:04:25)
==> box: Successfully added box 'precise32' (v0) for 'virtualbox'!
vagrant box add --provider virtualbox precise32 http://
files.vagrantup.com/precise32.box
➜ ~ vagrant box list
atomia/windows-2012R2 (virtualbox, 0.2.0)
precise32 (virtualbox, 0)
➜ ~ vagrant box list
atomia/windows-2012R2 (virtualbox, 0.2.0)
box-disk1.vmdk
box.ovf
metadata.json
Vagrantfile
28
Up and Running
(and destroying)
➜ ~ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'precise32'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: test_default_1430903546481_36514
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed on
default: your host and reload your VM.
default:
default: Guest Additions Version: 4.2.0
default: VirtualBox Version: 4.3
==> default: Mounting shared folders...
default: /vagrant => /Users/monkehworks/my_project
➜ ~
Bringing machine 'default' up with 'virtualbox' provider...
==> default: VirtualBox VM is already running.
vagrant up
➜ ~ vagrant status
Current machine states:
default running (virtualbox)
The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.
➜ ~
==> default: Saving VM state and suspending execution...
vagrant suspend
➜ ~ vagrant status
Current machine states:
default saved (virtualbox)
To resume this VM, simply run `vagrant up`.
➜ ~ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Resuming suspended VM...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection refused. Retrying...
==> default: Machine booted and ready!
➜ ~
==> default: Attempting graceful shutdown of VM...
vagrant halt
➜ ~ vagrant status
Current machine states:
default power (virtualbox)
The VM is powered off. To restart the VM, simply run `vagrant up`.
➜ ~ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed on
default: your host and reload your VM.
default:
default: Guest Additions Version: 4.2.0
default: VirtualBox Version: 4.3
==> default: Mounting shared folders...
default: /vagrant => /Users/monkehworks/my_project
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: to force provisioning. Provisioners marked to run always will still run.
➜ ~
==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...
vagrant destroy
➜ ~ vagrant status
Current machine states:
default not created (virtualbox)
default: Are you sure you want to destroy the 'default' VM? [y/N] y
The environment has not yet been created. Run `vagrant up` to
create the environment. If a machine is not created, only the
default provider will be shown. So if a provider is not listed,
then the machine is not created for that environment.
36
Connections
➜ ~ vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)
* Documentation: https://help.ubuntu.com/
New release '14.04.2 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
Welcome to your Vagrant-built virtual machine.
Last login: Wed May 6 13:56:45 2015 from 10.0.2.2
vagrant@precise32:~$ sudo su
root@precise32:/home/vagrant#
root@precise32:/home/vagrant# cat .ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr
+kz4TjGYe7gHzIw
+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYe
t2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4p
zC6kivAIhyfHilFR61RGL
+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm
+R4LOzFUGaHqHDLKLX
+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant
insecure public key
root@precise32:/home/vagrant# cat .ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr
+kz4TjGYe7gHzIw
+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYe
t2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4p
zC6kivAIhyfHilFR61RGL
+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm
+R4LOzFUGaHqHDLKLX
+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant
insecure public key
➜ ~ vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/monkehworks/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
➜ ~ vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/monkehworks/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
➜ ~ cat ~/.vagrant.d/insecure_private_key
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzI
w+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoP
kcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2
hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NO
Td0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcW
yLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQIBIwKCAQEA4iqWPJXtzZA68mKd
ELs4jJsdyky+ewdZeNds5tjcnHU5zUYE25K+ffJED9qUWICcLZDc81TGWjHyAqD1
Bw7XpgUwFgeUJwUlzQurAv+/ySnxiwuaGJfhFM1CaQHzfXphgVml+fZUvnJUTvzf
TK2Lg6EdbUE9TarUlBf/xPfuEhMSlIE5keb/Zz3/LUlRg8yDqz5w+QWVJ4utnKnK
iqwZN0mwpwU7YSyJhlT4YV1F3n4YjLswM5wJs2oqm0jssQu/BT0tyEXNDYBLEF4A
sClaWuSJ2kjq7KhrrYXzagqhnSei9ODYFShJu8UWVec3Ihb5ZXlzO6vdNQ1J9Xsf
4m+2ywKBgQD6qFxx/Rv9CNN96l/4rb14HKirC2o/orApiHmHDsURs5rUKDx0f9iP
cXN7S1uePXuJRK/5hsubaOCx3Owd2u9gD6Oq0CsMkE4CUSiJcYrMANtx54cGH7Rk
EjFZxK8xAv1ldELEyxrFqkbE4BKd8QOt414qjvTGyAK+OLD3M2QdCQKBgQDtx8pN
CAxR7yhHbIWT1AH66+XWN8bXq7l3RO/ukeaci98JfkbkxURZhtxV/HHuvUhnPLdX
3TwygPBYZFNo4pzVEhzWoTtnEtrFueKxyc3+LjZpuo+mBlQ6ORtfgkr9gBVphXZG
YEzkCD3lVdl8L4cw9BVpKrJCs1c5taGjDgdInQKBgHm/fVvv96bJxc9x1tffXAcj
3OVdUN0UgXNCSaf/3A/phbeBQe9xS+3mpc4r6qvx+iy69mNBeNZ0xOitIjpjBo2+
dBEjSBwLk5q5tJqHmy/jKMJL4n9ROlx93XS+njxgibTvU6Fp9w+NOFD/HvxB3Tcz
6+jJF85D5BNAG3DBMKBjAoGBAOAxZvgsKN+JuENXsST7F89Tck2iTcQIT8g5rwWC
P9Vt74yboe2kDT531w8+egz7nAmRBKNM751U/95P9t88EDacDI/Z2OwnuFQHCPDF
llYOUI+SpLJ6/vURRbHSnnn8a/XG+nzedGH5JGqEJNQsz+xT2axM0/W/CRknmGaJ
kda/AoGANWrLCz708y7VYgAtW2Uf1DPOIYMdvo6fxIB5i9ZfISgcJ/bbCUkFrhoH
+vq/5CIWxCPp0f85R4qxxQ5ihxJ0YDQT9Jpx4TMss4PSavPaBH3RXow5Ohe+bYoQ
NE5OgEXk2wVfZczCZpigBKbKZHNYcelXtTt/nP3rsCuGcM4h53s=
-----END RSA PRIVATE KEY-----
Portability
ITB2015 - Winning with Vagrant, Puppet and Chef
By sharing your Vagrantfile you
are essentially sharing your
development environment.
46
Infrastructure as
Code
47
VagrantïŹle
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg|
conïŹg.vm.box = "precise32"
conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box"
end
Networking
49
conïŹg.vm.network :public_network
Bridged Network
50
conïŹg.vm.network :forwarded_port, guest: 80, host: 8080
Port Forwarding
51
conïŹg.vm.network :private_network, ip: "192.168.10.10"
Private IP Space
52
Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg|
conïŹg.vm.box = "precise32"
conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box"
conïŹg.vm.network :private_network, ip: "192.168.10.10"
end
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'precise32'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: test_default_1431011744813_57334
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 22 => 2222 (adapter 1)
➜ ~ vagrant up
53
Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg|
conïŹg.vm.box = "precise32"
conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box"
conïŹg.vm.network :private_network, ip: "192.168.10.10"
end
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'precise32'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: test_default_1431011744813_57334
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 22 => 2222 (adapter 1)
➜ ~ vagrant up
54
Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg|
conïŹg.vm.box = "precise32"
conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box"
conïŹg.vm.network :forwarded_port, guest: 80, host: 8080
end
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'precise32'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: test_default_1431011744813_57334
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 80 => 8080 (adapter 1)
default: 22 => 2222 (adapter 1)
➜ ~ vagrant up
55
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'precise32'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: test_default_1431011744813_57334
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 80 => 8080 (adapter 1)
default: 22 => 2222 (adapter 1)
➜ ~ vagrant up
Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg|
conïŹg.vm.box = "precise32"
conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box"
conïŹg.vm.network :forwarded_port, guest: 80, host: 8080
end
56
Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg|
conïŹg.vm.box = "precise32"
conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box"
conïŹg.vm.network :public_network
end
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'precise32'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: test_default_1431012579630_44486
==> default: Clearing any previously set network interfaces...
==> default: Available bridged network interfaces:
1) en1: Wi-Fi (AirPort)
2) en0: Ethernet
3) p2p0
default: What interface should the network bridge to?
➜ ~ vagrant up
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: bridged
==> default: Forwarding ports...
1
57
➜ ~ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'precise32'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: test_default_1431012579630_44486
==> default: Clearing any previously set network interfaces...
==> default: Available bridged network interfaces:
1) en1: Wi-Fi (AirPort)
2) en0: Ethernet
3) p2p0
default: What interface should the network bridge to?
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: bridged
==> default: Forwarding ports...
1
Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg|
conïŹg.vm.box = "precise32"
conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box"
conïŹg.vm.network :public_network
end
58
➜ ~ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'precise32'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: test_default_1431012579630_44486
==> default: Clearing any previously set network interfaces...
==> default: Available bridged network interfaces:
1) en1: Wi-Fi (AirPort)
2) en0: Ethernet
3) p2p0
default: What interface should the network bridge to?
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: bridged
==> default: Forwarding ports...
1
Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg|
conïŹg.vm.box = "precise32"
conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box"
conïŹg.vm.network "public_network", :bridge => 'en1: Wi-‐Fi (AirPort)'
end
Synced Folders
==> default: Mounting shared folders...
default: /vagrant => /Users/monkehworks/my_project
Mount Management
conïŹg.vm.synced_folder "htdocs/", "/var/www"
==> default: Mounting shared folders

default: /var/www => /Users/monkehworks/my_project/htdocs
default: /vagrant => /Users/monkehworks/my_project
VM Properties
config.vm.hostname = "mymachine"
config.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, '-‐chipset', 'ich9']
v.customize ["modifyvm", :id, "-‐natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "-‐ioapic", "on"]
v.customize ["modifyvm", :id, "-‐memory", 2048]
v.customize ["modifyvm", :id, "-‐cpus", "4"]
#v.gui = true
end
Provisioning
Add specific software
Create configuration files
Execute commands
Create users
Manage services
Automatically executed on vagrant up
Aim to have an exact
(or as close as possible)
copy of your production
environment
Shell
Ansible
Chef Solo
Chef Client
Puppet Apply
Puppet Agent
Shell Provisioning
config.vm.provision :shell, :inline =>
"mount ‐t tmpfs ‐o size=50m,mode=0777 tmpfs /vagrant/ app/cache"
# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<SCRIPT
echo I am provisioning...
date > /etc/vagrant_provisioned_at
SCRIPT
VAGRANTFILE_API_VERSION = "2"
Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg|
conïŹg.vm.box = "precise32"
conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box"
conïŹg.vm.provision :shell, :inline $script
end
config.vm.provision "shell", path: "script.sh"
config.vm.provision "shell", path: "https://example.com/provisioner.sh"
External Scripts
ITB2015 - Winning with Vagrant, Puppet and Chef
ITB2015 - Winning with Vagrant, Puppet and Chef
ITB2015 - Winning with Vagrant, Puppet and Chef
Written in Ruby
Open source with enterprise revenue model
Similar features
Both have a standalone and server-side edition
Supported by a large community
Modularized components
Use packages for software installs
Use templating for custom files
Filesystem methods
and more

Chef & Puppet
Chef Puppet
Modules Cookbooks Modules
Actions Recipes Manifests
Language Ruby extended with DSL DSL
Running order Sequential “Random”
Approach Define actions Define state
Programming style Procedural “OO-esque”
An Intro to Chef
Download cookbooks
- https://github.com/opscode-cookbooks
Configure chef.cookbooks_path in Vagrantfile
Add recipes using chef.add_recipe in Vagrantfile
Configure attributes with chef.json
Group custom actions in custom cookbook
Using Chef Solo
VagrantïŹle
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "./tools/chef/cookbooks"
chef.add_recipe "mysql::server"
chef.json = {
"mysql" => {
"server_root_password" => "foo",
"server_repl_password" => "foo",
"server_debian_password" => "foo"
}
}
end
cookbook
├── README.md
├── attributes
├── definitions
├── files
│ └── default
├── libraries
├── metadata.rb
├── providers
├── recipes
│ └── default.rb
├── resources
└── templates
└── default
default['mysql']['port'] = 3306
default['mysql']['nice'] = 0
case node['platform_family']
when 'debian'
default['mysql']['server']['packages'] = %w[mysql-server]
default['mysql']['service_name'] = 'mysql'
default['mysql']['basedir'] = '/usr'
default['mysql']['data_dir'] = '/var/lib/mysql'
default['mysql']['root_group'] = 'root'
default['mysql']['mysqladmin_bin'] = '/usr/bin/mysqladmin'
default['mysql']['mysql_bin'] = '/usr/bin/mysql'
default['mysql']['conf_dir'] = '/etc/mysql'
default['mysql']['confd_dir'] = '/etc/mysql/conf.d'
default['mysql']['socket'] = '/var/run/mysqld/mysqld.sock'
default['mysql']['pid_file'] = '/var/run/mysqld/mysqld.pid'
default['mysql']['old_passwords'] = 0
default['mysql']['grants_path'] = '/etc/mysql/grants.sql'
MySQL Attributes
...
group 'mysql' do
action :create
end
user 'mysql' do
comment 'MySQL Server'
gid 'mysql'
system true
home node['mysql']['data_dir']
shell '/sbin/nologin'
end
node['mysql']['server']['packages'].each do |name|
package name do
action :install
notifies :start, 'service[mysql]', :immediately
end
end
...
MySQL Server Recipe
[client]
host user = localhost
= debian-sys-maint
password = <%= node['mysql']['server_debian_password'] %>
socket = <%= node['mysql']['socket'] %>
[mysql_upgrade]
host = localhost
user = debian‐sys-maint
password = <%= node['mysql']['server_debian_password'] %>
socket = <%= node['mysql']['socket'] %>
basedir = /usr
MySQL Template
Cron
Directory
Execute
File
Git
Group
Link
Log
Package
Service
Template
User
and more...
Typical Chef resources
Cooking for yourself
execute 'update apt' do command "apt‐get update"
action :run
end
package 'mysql-server' do
action :install
notifies :start, 'service[mysql]', :immediately
end
package 'apache2' do
action :install
notifies :start, 'service[apache2]', :delayed
end
package 'php5' do
action :install
notifies :reload, 'service[apache2]', :delayed
end
./tools/chef/cookbooks/project/recipes/default.rb
execute 'assign‐root‐password' do
command "/usr/bin/mysqladmin -u root password ‘#{node['project']
['server_root_password']}'"
action :run
only_if "/usr/bin/mysql -u root -e 'show databases;'"
end
service 'mysql' do
service_name 'mysql'
supports :status => true, :restart => true, :reload => true
action :enable
end
service 'apache2' do
service_name 'apache2'
supports :status => true, :restart => true, :reload => true
action :enable
end
./tools/chef/cookbooks/project/recipes/default.rb
VagrantïŹle
VAGRANTFILE_API_VERSION = "2"
Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg|
conïŹg.vm.box = "precise32"
conïŹg.vm.box_url = “http://ïŹles.vagrantup.com/precise32.box"
conïŹg.vm.synced_folder "htdocs/", "/var/www"
conïŹg.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "./tools/chef/cookbooks"
chef.add_recipe "project"
chef.json = {
"project" => {
"server_root_password" => "foo"
}
}
end
end
➜ ~ vagrant up
...
==> default: Mounting shared folders

default: /var/www => /Users/monkehworks/my_project/htdocs
default: /vagrant => /Users/monkehworks/my_project
==> default: /tmp/vagrant-chef-1/chef-solo-1/cookbooks
==> default: Running provisioner: chef_solo

Generating chef JSON and uploading

Running chef-solo

...
ITB2015 - Winning with Vagrant, Puppet and Chef
An Intro to Puppet
Download modules
- https://forge.puppetlabs.com
Configure in Vagrantfile:
- puppet.module_path
- puppet.manifests_path
- puppet.manifest_file
Provisioning flow happens in the main manifest
Configure attributes with puppet.facter
Using Puppet Apply
VagrantïŹle
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "./tools/puppet/manifests"
puppet.module_path = "./tools/puppet/modules"
puppet.manifest_file = "init.pp"
puppet.options = ['--verbose']
end
init.pp
include mysql::server
class {
'::mysql::server' :root_password => 'foo'
}
module
├── README.md
├── files
├── lib
├──
metadata.json
├── spec
├── manifests
│ └── init.pp
│ └──
params.pp
├── resources
└── templates
└── tests
MySQL Params
class mysql::params {
$manage_config_file = true
$old_root_password = ''
$purge_conf_dir = false
$restart = false
$root_password = 'UNSET'
$server_package_ensure = 'present'
$server_service_manage = true
$server_service_enabled = true
# mysql::bindings
$bindings_enable = false
$java_package_ensure = 'present'
$java_package_provider = undef
$perl_package_ensure = 'present'
$perl_package_provider = undef
$php_package_ensure = 'present'
$php_package_provider = undef
$python_package_ensure = 'present'
$python_package_provider = undef
$ruby_package_ensure = 'present'
$ruby_package_provider = undef
MySQL server manifest
class mysql::server (
$config_file = $mysql::params::config_file
$manage_config_file = $mysql::params::manage_config_file
$old_root_password = $mysql::params::old_root_password,
$override_options = {},
$package_ensure = $mysql::params::server_package_ensure,
$package_name = $mysql::params::server_package_name,
$purge_conf_dir = $mysql::params::purge_conf_dir,
$remove_default_accounts = false,
$restart = $mysql::params::restart,
$root_group = $mysql::params::root_group,
$root_password = $mysql::params::root_password,
$service_enabled = $mysql::params::server_service_enabled,
$service_manage = $mysql::params::server_service_manage,
$service_name = $mysql::params::server_service_name,
$service_provider = $mysql::params::server_service_provider,
# Deprecated parameters
$enabled = undef,
$manage_service = undef
) inherits mysql::params {
...
[client]
user=root
host=localhost
<% unless scope.lookupvar('mysql::server::root_password') == 'UNSET' ‐%>
password='<%= scope.lookupvar('mysql::server::root_password') %>'
<% end ‐%>
socket=<%= @options['client']['socket'] ‐%>
MySQL Template
Computer
Cron
Exec
File
Filebucket
Group
Host
Interface
Package
Service
Sshkey
User
and more

Typical Puppet resources
Pulling your own
strings
exec { "apt‐update":
command => "/usr/bin/apt-get update",
}
package { 'mysql‐server':
ensure => present,
require => Exec['apt‐update'],
notify => Service['mysql'],
}
package { 'apache2':
ensure => present,
require => Exec['apt‐update'],
notify => Package['php5'],
}
package { 'php5':
ensure => present,
require => Exec['apt‐update'],
notify => Service['apache2'],
}
./tools/puppet/manifests/init.pp
./tools/puppet/manifests/init.pp
exec {'assign‐root‐password':
command => "/usr/bin/mysqladmin ‐u root password $root_password",
require => Package["mysql‐server"],
onlyif => "/usr/bin/mysql ‐u root ‐e 'show databases;'"
}
service { "mysql":
name => "mysql",
ensure => running,
enable => true,
hasrestart => true,
require => Package["mysql‐server"],
}
service { "apache2":
name => "apache2",
ensure => running,
enable => true,
hasrestart => true,
require => Package["apache2"],
}
VagrantïŹle
VAGRANTFILE_API_VERSION = "2"
Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg|
conïŹg.vm.box = "precise32"
conïŹg.vm.box_url = “http://ïŹles.vagrantup.com/precise32.box"
conïŹg.vm.synced_folder "htdocs/", "/var/www"
conïŹg.vm.provision :puppet do |puppet|
puppet.manifests_path = "./tools/puppet/manifests"
puppet.module_path = "./tools/puppet/modules"
puppet.manifest_file = “init.pp"
puppet.facter = {
“root_password” => “foo”,
}
puppet.options = ['--verbose']
end
end
ITB2015 - Winning with Vagrant, Puppet and Chef
ITB2015 - Winning with Vagrant, Puppet and Chef
(when machine is running)
➜ ~ vagrant provision
Problems with
Provisioning
Provisioning is often slow
Quality of public cookbooks/manifests
Support on cookbooks/manifests
Writing it yourself can be difficult
Distribution restrictions
➜ ~ vagrant package
Possible solution for slow provisioning
Is not the same as vagrant box repackage
Use exported box as new base box
No provisioning required on startup
Possibility of doing “light” provisioning instead
ITB2015 - Winning with Vagrant, Puppet and Chef
Multi-Machine Setup
VAGRANTFILE_API_VERSION = "2"
Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg|
conïŹg.vm.provision "shell", inline: "/usr/bin/apt‐get update"
conïŹg.vm.box = "debian‐7.1.0"
conïŹg.vm.deïŹne "web", primary: true do |web|
web.vm.hostname = "web"
web.vm.network :private_network, ip: "192.168.33.10"
web.vm.synced_folder "htdocs/", "/var/www"
web.vm.provision :puppet do |puppet|
puppet.manifests_path = "./tools/puppet/manifests"
puppet.module_path = "./tools/puppet/modules"
puppet.manifest_ïŹle = "web.pp"
puppet.options = ['-‐verbose']
end
end
conïŹg.vm.deïŹne "db" do |db|
db.vm.hostname = "db"
db.vm.network :private_network, ip: "192.168.33.11"
db.vm.provision :puppet do |puppet|
puppet.manifests_path = "./tools/puppet/manifests"
puppet.module_path = "./tools/puppet/modules"
puppet.manifest_ïŹle = "db.pp"
puppet.options = ['-‐verbose']
puppet.facter = {
"root_password" => "foo",
}
end
end
VAGRANTFILE_API_VERSION = "2"
Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg|
conïŹg.vm.provision "shell", inline: "/usr/bin/apt‐get update"
conïŹg.vm.box = "debian‐7.1.0"
conïŹg.vm.deïŹne "web", primary: true do |web|
web.vm.hostname = "web"
web.vm.network :private_network, ip: "192.168.33.10"
web.vm.synced_folder "htdocs/", "/var/www"
web.vm.provision :puppet do |puppet|
puppet.manifests_path = "./tools/puppet/manifests"
puppet.module_path = "./tools/puppet/modules"
puppet.manifest_ïŹle = "web.pp"
puppet.options = ['-‐verbose']
end
end
conïŹg.vm.deïŹne "db" do |db|
db.vm.hostname = "db"
db.vm.network :private_network, ip: "192.168.33.11"
db.vm.provision :puppet do |puppet|
puppet.manifests_path = "./tools/puppet/manifests"
puppet.module_path = "./tools/puppet/modules"
puppet.manifest_ïŹle = "db.pp"
puppet.options = ['-‐verbose']
puppet.facter = {
"root_password" => "foo",
}
end
end
ITB2015 - Winning with Vagrant, Puppet and Chef
ITB2015 - Winning with Vagrant, Puppet and Chef
➜ ~ vagrant up
➜ ~ vagrant destroy
➜ ~ vagrant ssh
➜ ~ vagrant up web
➜ ~ vagrant ssh web
➜ ~ vagrant destroy web
➜ ~ vagrant up db
➜ ~ vagrant ssh db
➜ ~ vagrant destroy db
ColdFusion and
Vagrant
https://github.com/lewg/cfenv-chef
https://github.com/davejlong/vagrant-boxes
https://github.com/mikesprague/vagrant-lemtl
https://github.com/bdcravens/railo-vagrant
https://github.com/gratzc/it-works-on-my-machine-chef-vagrant
ITB2015 - Winning with Vagrant, Puppet and Chef
#WINNING

More Related Content

PDF
DevOps(2) : Vagrant - (MOSG)
PDF
Preparation study of_docker - (MOSG)
PDF
DevOps(4) : Ansible(2) - (MOSG)
PDF
Instruction: dev environment
KEY
Puppet for Java developers - JavaZone NO 2012
PDF
Red hat lvm cheatsheet
KEY
From Dev to DevOps - FOSDEM 2012
PDF
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
DevOps(2) : Vagrant - (MOSG)
Preparation study of_docker - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)
Instruction: dev environment
Puppet for Java developers - JavaZone NO 2012
Red hat lvm cheatsheet
From Dev to DevOps - FOSDEM 2012
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013

What's hot (19)

PDF
DevOps(3) : Ansible - (MOSG)
PDF
The New MariaDB Offering - MariaDB 10, MaxScale and more
KEY
From Dev to DevOps - Apache Barcamp Spain 2011
KEY
From Dev to DevOps - ApacheCON NA 2011
PDF
From Dev to DevOps - Codemotion ES 2012
PDF
How to Develop Puppet Modules: From Source to the Forge With Zero Clicks
PDF
Making environment for_infrastructure_as_code
PDF
PuppetConf 2016: Nano Server, Puppet, and DSC
PDF
Fabric workshop(1) - (MOSG)
PDF
Vagrant for real (codemotion rome 2016)
PDF
Putting some "logic" in LVM.
PDF
Continuous Delivery: The Next Frontier
PDF
Test driven infrastructure
PPTX
Tribal Nova Docker workshop
PDF
Continuous infrastructure testing
PDF
Ansible ćŻŠæˆ°ïŒštop down 觀點
PDF
Kickin' Ass with Cache-Fu (without notes)
 
PDF
Security Testing Using Infrastructure-As-Code
DevOps(3) : Ansible - (MOSG)
The New MariaDB Offering - MariaDB 10, MaxScale and more
From Dev to DevOps - Apache Barcamp Spain 2011
From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - Codemotion ES 2012
How to Develop Puppet Modules: From Source to the Forge With Zero Clicks
Making environment for_infrastructure_as_code
PuppetConf 2016: Nano Server, Puppet, and DSC
Fabric workshop(1) - (MOSG)
Vagrant for real (codemotion rome 2016)
Putting some "logic" in LVM.
Continuous Delivery: The Next Frontier
Test driven infrastructure
Tribal Nova Docker workshop
Continuous infrastructure testing
Ansible ćŻŠæˆ°ïŒštop down 觀點
Kickin' Ass with Cache-Fu (without notes)
 
Security Testing Using Infrastructure-As-Code
Ad

Viewers also liked (20)

PDF
ITB2015 - Customizing ContentBox with Themes, Widgets, and Modules, Oh My!
PDF
ITB2015 - Behavior Driven Development, Automation and Continuous Integration
PDF
ITB2015 - ColdBox 4 MVC Modular Architecture
PDF
ORM Pink Unicorns
PPTX
ITB2015 - NoSQL For You And Me
PPTX
ITB2015 - Go Commando with CommandBox CLI
PDF
ITB2015 - Monitoring and Tracking Your Web Applications
PDF
ITB2015 - Crash Course in Ionic + AngularJS
PDF
ITB2015 - Real Life ContentBox Modular CMS
PPTX
êłŒì œ
PPTX
Sinister
PDF
ITB2016 Intro To ColdBox MVC
PPTX
Storyboard (day 1 of filming)
PPTX
Michael Jackson
PDF
Social Media Strategy: Exploring the Basics
PPTX
Presentation1 achu 2
DOCX
Planning booklet
PPTX
è©±éĄŒć‘Œ
 
PDF
Where to find $59 Trillion: A Map for Nonprofits
PPTX
Star wars return of the jedi
ITB2015 - Customizing ContentBox with Themes, Widgets, and Modules, Oh My!
ITB2015 - Behavior Driven Development, Automation and Continuous Integration
ITB2015 - ColdBox 4 MVC Modular Architecture
ORM Pink Unicorns
ITB2015 - NoSQL For You And Me
ITB2015 - Go Commando with CommandBox CLI
ITB2015 - Monitoring and Tracking Your Web Applications
ITB2015 - Crash Course in Ionic + AngularJS
ITB2015 - Real Life ContentBox Modular CMS
êłŒì œ
Sinister
ITB2016 Intro To ColdBox MVC
Storyboard (day 1 of filming)
Michael Jackson
Social Media Strategy: Exploring the Basics
Presentation1 achu 2
Planning booklet
è©±éĄŒć‘Œ
 
Where to find $59 Trillion: A Map for Nonprofits
Star wars return of the jedi
Ad

Similar to ITB2015 - Winning with Vagrant, Puppet and Chef (20)

PDF
Quick & Easy Dev Environments with Vagrant
PPTX
Vagrant-Overview
PPTX
Vagrant step-by-step guide for Beginners
PDF
vagrant-php
PDF
FreeBSD: Dev to Prod
PDF
Create Development and Production Environments with Vagrant
PPTX
Environments line-up! Vagrant & Puppet 101
PPTX
Vagrant 101 Workshop
PDF
Puppet and Vagrant in development
PDF
How I hack on puppet modules
PDF
Vagrant for real
PDF
Vagrant for real codemotion (moar tips! ;-))
PDF
Vm ware server-tips-tricks
PDF
Vmwareserver tips-tricks-110218231744-phpapp01
PDF
Virtual Infrastructure
PPTX
DevOps Hackathon - Session 1: Vagrant
PPTX
Vagrant introduction for Developers
DOCX
Run Docker On Windows Using Vagrant
PDF
Intro to vagrant
PDF
Minicurso de Vagrant
Quick & Easy Dev Environments with Vagrant
Vagrant-Overview
Vagrant step-by-step guide for Beginners
vagrant-php
FreeBSD: Dev to Prod
Create Development and Production Environments with Vagrant
Environments line-up! Vagrant & Puppet 101
Vagrant 101 Workshop
Puppet and Vagrant in development
How I hack on puppet modules
Vagrant for real
Vagrant for real codemotion (moar tips! ;-))
Vm ware server-tips-tricks
Vmwareserver tips-tricks-110218231744-phpapp01
Virtual Infrastructure
DevOps Hackathon - Session 1: Vagrant
Vagrant introduction for Developers
Run Docker On Windows Using Vagrant
Intro to vagrant
Minicurso de Vagrant

More from Ortus Solutions, Corp (20)

PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
PDF
June Webinar: BoxLang-Dynamic-AWS-Lambda
PDF
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
PDF
What's-New-with-BoxLang-Brad Wood.pptx.pdf
PDF
Getting Started with BoxLang - CFCamp 2025.pdf
PDF
CFCamp2025 - Keynote Day 1 led by Luis Majano.pdf
PDF
What's New with BoxLang Led by Brad Wood.pdf
PDF
Vector Databases and the BoxLangCFML Developer.pdf
PDF
Using cbSSO in a ColdBox App Led by Jacob Beers.pdf
PDF
Use JSON to Slash Your Database Performance.pdf
PDF
Portable CI wGitLab and Github led by Gavin Pickin.pdf
PDF
Tame the Mesh An intro to cross-platform tracing and troubleshooting.pdf
PDF
Supercharging CommandBox with Let's Encrypt.pdf
PDF
Spice up your site with cool animations using GSAP..pdf
PDF
Passkeys and cbSecurity Led by Eric Peterson.pdf
PDF
Legacy Code Nightmares , Hellscapes, and Lessons Learned.pdf
PDF
Integrating the OpenAI API in Your Coldfusion Apps.pdf
PDF
Hidden Gems in FusionReactor for BoxLang, ACF, and Lucee Users.pdf
PDF
Geting-started with BoxLang Led By Raymon Camden.pdf
PDF
From Zero to CRUD with ORM - Led by Annette Liskey.pdf
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
June Webinar: BoxLang-Dynamic-AWS-Lambda
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
What's-New-with-BoxLang-Brad Wood.pptx.pdf
Getting Started with BoxLang - CFCamp 2025.pdf
CFCamp2025 - Keynote Day 1 led by Luis Majano.pdf
What's New with BoxLang Led by Brad Wood.pdf
Vector Databases and the BoxLangCFML Developer.pdf
Using cbSSO in a ColdBox App Led by Jacob Beers.pdf
Use JSON to Slash Your Database Performance.pdf
Portable CI wGitLab and Github led by Gavin Pickin.pdf
Tame the Mesh An intro to cross-platform tracing and troubleshooting.pdf
Supercharging CommandBox with Let's Encrypt.pdf
Spice up your site with cool animations using GSAP..pdf
Passkeys and cbSecurity Led by Eric Peterson.pdf
Legacy Code Nightmares , Hellscapes, and Lessons Learned.pdf
Integrating the OpenAI API in Your Coldfusion Apps.pdf
Hidden Gems in FusionReactor for BoxLang, ACF, and Lucee Users.pdf
Geting-started with BoxLang Led By Raymon Camden.pdf
From Zero to CRUD with ORM - Led by Annette Liskey.pdf

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Electronic commerce courselecture one. Pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
 
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
KodekX | Application Modernization Development
 
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
cuic standard and advanced reporting.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
 
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java ‱ Spring Boot ‱ Ka...
PDF
Empathic Computing: Creating Shared Understanding
PPTX
MYSQL Presentation for SQL database connectivity
DOCX
The AUB Centre for AI in Media Proposal.docx
 
“AI and Expert System Decision Support & Business Intelligence Systems”
Electronic commerce courselecture one. Pdf
NewMind AI Weekly Chronicles - August'25 Week I
The Rise and Fall of 3GPP – Time for a Sabbatical?
 
Per capita expenditure prediction using model stacking based on satellite ima...
Understanding_Digital_Forensics_Presentation.pptx
KodekX | Application Modernization Development
 
Dropbox Q2 2025 Financial Results & Investor Presentation
cuic standard and advanced reporting.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Reach Out and Touch Someone: Haptics and Empathic Computing
Diabetes mellitus diagnosis method based random forest with bat algorithm
CIFDAQ's Market Insight: SEC Turns Pro Crypto
 
Advanced methodologies resolving dimensionality complications for autism neur...
Chapter 3 Spatial Domain Image Processing.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Shreyas Phanse Resume: Experienced Backend Engineer | Java ‱ Spring Boot ‱ Ka...
Empathic Computing: Creating Shared Understanding
MYSQL Presentation for SQL database connectivity
The AUB Centre for AI in Media Proposal.docx
 

ITB2015 - Winning with Vagrant, Puppet and Chef

  • 4. Create and configure lightweight, reproducible, and portable development environments.
  • 9. Environment per project Dev ~= Test ~= Staging ~= Production Easy to define & transport Easy to tear down Provisionable Versionable Shared across the team
  • 10. ➜ ~ Usage: vagrant [options] <command> [<args>] -v, --version Print the version and exit. -h, --help Print this help. vagrant Common commands: box manages boxes: installation, removal, etc. connect connect to a remotely shared Vagrant environment destroy stops and deletes all traces of the vagrant machine global-status outputs status Vagrant environments for this user halt stops the vagrant machine help shows the help for a subcommand init initializes a new Vagrant environment by creating a Vagrantfile login log in to Vagrant Cloud package packages a running vagrant environment into a box plugin manages plugins: install, uninstall, update, etc. provision provisions the vagrant machine rdp connects to machine via RDP reload restarts vagrant machine, loads new Vagrantfile configuration resume resume a suspended vagrant machine share share your Vagrant environment with anyone in the world ssh connects to machine via SSH ssh-config outputs OpenSSH valid configuration to connect to the machine status outputs status of the vagrant machine suspend suspends the machine up starts and provisions the vagrant environment version prints current and latest Vagrant version
  • 11. For help on any individual command run `vagrant COMMAND -h` Additional subcommands are available, but are either more advanced or not commonly used. To see all subcommands, run the command `vagrant list-commands`.
  • 13. Select base box Choose virtualization provider Configure VM parameters Configure networking Tweak SSH settings Mount local folders Provision machine
  • 14. ➜ ~ Usage: vagrant init [options] [name [url]] Options: -f, --force Overwrite existing Vagrantfile -m, --minimal Create minimal Vagrantfile (no help comments) --output FILE Output path for the box. '-' for stdout -h, --help Print this help vagrant init -h ➜ ~ vagrant init A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant.
  • 15. 15 Vagrantfile # -*- mode: ruby -*- # vi: set ft=ruby : VAGRANTFILE_API_VERSION = "2" Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg| conïŹg.vm.box = "base" end
  • 16. ➜ ~ vagrant init precise32 http://files.vagrantup.com/precise32.box A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant.
  • 17. 17 VagrantïŹle # -*- mode: ruby -*- # vi: set ft=ruby : VAGRANTFILE_API_VERSION = "2" Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg| conïŹg.vm.box = "precise32" conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box" end
  • 18. Boxes
  • 25. ➜ ~ Usage: vagrant box <subcommand> [<args>] Available subcommands: add list outdated remove repackage update vagrant box
  • 26. ➜ ~ ==> box: Adding box 'precise32' (v0) for provider: virtualbox box: Downloading: http://files.vagrantup.com/precise32.box box: Progress: 38% (Rate: 615k/s, Estimated time remaining: 0:04:25) ==> box: Successfully added box 'precise32' (v0) for 'virtualbox'! vagrant box add --provider virtualbox precise32 http:// files.vagrantup.com/precise32.box ➜ ~ vagrant box list atomia/windows-2012R2 (virtualbox, 0.2.0) precise32 (virtualbox, 0) ➜ ~ vagrant box list atomia/windows-2012R2 (virtualbox, 0.2.0)
  • 28. 28 Up and Running (and destroying)
  • 29. ➜ ~ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'precise32'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: test_default_1430903546481_36514 ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 22 => 2222 (adapter 1) ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Connection timeout. Retrying... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... default: The guest additions on this VM do not match the installed version of default: VirtualBox! In most cases this is fine, but in rare cases it can default: prevent things such as shared folders from working properly. If you see default: shared folder errors, please make sure the guest additions within the default: virtual machine match the version of VirtualBox you have installed on default: your host and reload your VM. default: default: Guest Additions Version: 4.2.0 default: VirtualBox Version: 4.3 ==> default: Mounting shared folders... default: /vagrant => /Users/monkehworks/my_project
  • 30. ➜ ~ Bringing machine 'default' up with 'virtualbox' provider... ==> default: VirtualBox VM is already running. vagrant up ➜ ~ vagrant status Current machine states: default running (virtualbox) The VM is running. To stop this VM, you can run `vagrant halt` to shut it down forcefully, or you can run `vagrant suspend` to simply suspend the virtual machine. In either case, to restart it again, simply run `vagrant up`.
  • 31. ➜ ~ ==> default: Saving VM state and suspending execution... vagrant suspend ➜ ~ vagrant status Current machine states: default saved (virtualbox) To resume this VM, simply run `vagrant up`.
  • 32. ➜ ~ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Resuming suspended VM... ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Connection refused. Retrying... ==> default: Machine booted and ready!
  • 33. ➜ ~ ==> default: Attempting graceful shutdown of VM... vagrant halt ➜ ~ vagrant status Current machine states: default power (virtualbox) The VM is powered off. To restart the VM, simply run `vagrant up`.
  • 34. ➜ ~ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 22 => 2222 (adapter 1) ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Connection timeout. Retrying... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... default: The guest additions on this VM do not match the installed version of default: VirtualBox! In most cases this is fine, but in rare cases it can default: prevent things such as shared folders from working properly. If you see default: shared folder errors, please make sure the guest additions within the default: virtual machine match the version of VirtualBox you have installed on default: your host and reload your VM. default: default: Guest Additions Version: 4.2.0 default: VirtualBox Version: 4.3 ==> default: Mounting shared folders... default: /vagrant => /Users/monkehworks/my_project ==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision` ==> default: to force provisioning. Provisioners marked to run always will still run.
  • 35. ➜ ~ ==> default: Forcing shutdown of VM... ==> default: Destroying VM and associated drives... vagrant destroy ➜ ~ vagrant status Current machine states: default not created (virtualbox) default: Are you sure you want to destroy the 'default' VM? [y/N] y The environment has not yet been created. Run `vagrant up` to create the environment. If a machine is not created, only the default provider will be shown. So if a provider is not listed, then the machine is not created for that environment.
  • 37. ➜ ~ vagrant ssh Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686) * Documentation: https://help.ubuntu.com/ New release '14.04.2 LTS' available. Run 'do-release-upgrade' to upgrade to it. Welcome to your Vagrant-built virtual machine. Last login: Wed May 6 13:56:45 2015 from 10.0.2.2 vagrant@precise32:~$ sudo su root@precise32:/home/vagrant#
  • 38. root@precise32:/home/vagrant# cat .ssh/authorized_keys ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr +kz4TjGYe7gHzIw +niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYe t2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4p zC6kivAIhyfHilFR61RGL +GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm +R4LOzFUGaHqHDLKLX +FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
  • 39. root@precise32:/home/vagrant# cat .ssh/authorized_keys ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr +kz4TjGYe7gHzIw +niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYe t2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4p zC6kivAIhyfHilFR61RGL +GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm +R4LOzFUGaHqHDLKLX +FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
  • 40. ➜ ~ vagrant ssh-config Host default HostName 127.0.0.1 User vagrant Port 2222 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile /Users/monkehworks/.vagrant.d/insecure_private_key IdentitiesOnly yes LogLevel FATAL
  • 41. ➜ ~ vagrant ssh-config Host default HostName 127.0.0.1 User vagrant Port 2222 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile /Users/monkehworks/.vagrant.d/insecure_private_key IdentitiesOnly yes LogLevel FATAL
  • 42. ➜ ~ cat ~/.vagrant.d/insecure_private_key -----BEGIN RSA PRIVATE KEY----- MIIEogIBAAKCAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzI w+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoP kcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2 hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NO Td0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcW yLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQIBIwKCAQEA4iqWPJXtzZA68mKd ELs4jJsdyky+ewdZeNds5tjcnHU5zUYE25K+ffJED9qUWICcLZDc81TGWjHyAqD1 Bw7XpgUwFgeUJwUlzQurAv+/ySnxiwuaGJfhFM1CaQHzfXphgVml+fZUvnJUTvzf TK2Lg6EdbUE9TarUlBf/xPfuEhMSlIE5keb/Zz3/LUlRg8yDqz5w+QWVJ4utnKnK iqwZN0mwpwU7YSyJhlT4YV1F3n4YjLswM5wJs2oqm0jssQu/BT0tyEXNDYBLEF4A sClaWuSJ2kjq7KhrrYXzagqhnSei9ODYFShJu8UWVec3Ihb5ZXlzO6vdNQ1J9Xsf 4m+2ywKBgQD6qFxx/Rv9CNN96l/4rb14HKirC2o/orApiHmHDsURs5rUKDx0f9iP cXN7S1uePXuJRK/5hsubaOCx3Owd2u9gD6Oq0CsMkE4CUSiJcYrMANtx54cGH7Rk EjFZxK8xAv1ldELEyxrFqkbE4BKd8QOt414qjvTGyAK+OLD3M2QdCQKBgQDtx8pN CAxR7yhHbIWT1AH66+XWN8bXq7l3RO/ukeaci98JfkbkxURZhtxV/HHuvUhnPLdX 3TwygPBYZFNo4pzVEhzWoTtnEtrFueKxyc3+LjZpuo+mBlQ6ORtfgkr9gBVphXZG YEzkCD3lVdl8L4cw9BVpKrJCs1c5taGjDgdInQKBgHm/fVvv96bJxc9x1tffXAcj 3OVdUN0UgXNCSaf/3A/phbeBQe9xS+3mpc4r6qvx+iy69mNBeNZ0xOitIjpjBo2+ dBEjSBwLk5q5tJqHmy/jKMJL4n9ROlx93XS+njxgibTvU6Fp9w+NOFD/HvxB3Tcz 6+jJF85D5BNAG3DBMKBjAoGBAOAxZvgsKN+JuENXsST7F89Tck2iTcQIT8g5rwWC P9Vt74yboe2kDT531w8+egz7nAmRBKNM751U/95P9t88EDacDI/Z2OwnuFQHCPDF llYOUI+SpLJ6/vURRbHSnnn8a/XG+nzedGH5JGqEJNQsz+xT2axM0/W/CRknmGaJ kda/AoGANWrLCz708y7VYgAtW2Uf1DPOIYMdvo6fxIB5i9ZfISgcJ/bbCUkFrhoH +vq/5CIWxCPp0f85R4qxxQ5ihxJ0YDQT9Jpx4TMss4PSavPaBH3RXow5Ohe+bYoQ NE5OgEXk2wVfZczCZpigBKbKZHNYcelXtTt/nP3rsCuGcM4h53s= -----END RSA PRIVATE KEY-----
  • 45. By sharing your Vagrantfile you are essentially sharing your development environment.
  • 47. 47 VagrantïŹle # -*- mode: ruby -*- # vi: set ft=ruby : VAGRANTFILE_API_VERSION = "2" Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg| conïŹg.vm.box = "precise32" conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box" end
  • 50. 50 conïŹg.vm.network :forwarded_port, guest: 80, host: 8080 Port Forwarding
  • 51. 51 conïŹg.vm.network :private_network, ip: "192.168.10.10" Private IP Space
  • 52. 52 Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg| conïŹg.vm.box = "precise32" conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box" conïŹg.vm.network :private_network, ip: "192.168.10.10" end Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'precise32'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: test_default_1431011744813_57334 ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: hostonly ==> default: Forwarding ports... default: 22 => 2222 (adapter 1) ➜ ~ vagrant up
  • 53. 53 Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg| conïŹg.vm.box = "precise32" conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box" conïŹg.vm.network :private_network, ip: "192.168.10.10" end Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'precise32'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: test_default_1431011744813_57334 ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: hostonly ==> default: Forwarding ports... default: 22 => 2222 (adapter 1) ➜ ~ vagrant up
  • 54. 54 Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg| conïŹg.vm.box = "precise32" conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box" conïŹg.vm.network :forwarded_port, guest: 80, host: 8080 end Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'precise32'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: test_default_1431011744813_57334 ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 80 => 8080 (adapter 1) default: 22 => 2222 (adapter 1) ➜ ~ vagrant up
  • 55. 55 Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'precise32'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: test_default_1431011744813_57334 ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 80 => 8080 (adapter 1) default: 22 => 2222 (adapter 1) ➜ ~ vagrant up Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg| conïŹg.vm.box = "precise32" conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box" conïŹg.vm.network :forwarded_port, guest: 80, host: 8080 end
  • 56. 56 Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg| conïŹg.vm.box = "precise32" conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box" conïŹg.vm.network :public_network end Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'precise32'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: test_default_1431012579630_44486 ==> default: Clearing any previously set network interfaces... ==> default: Available bridged network interfaces: 1) en1: Wi-Fi (AirPort) 2) en0: Ethernet 3) p2p0 default: What interface should the network bridge to? ➜ ~ vagrant up ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: bridged ==> default: Forwarding ports... 1
  • 57. 57 ➜ ~ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'precise32'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: test_default_1431012579630_44486 ==> default: Clearing any previously set network interfaces... ==> default: Available bridged network interfaces: 1) en1: Wi-Fi (AirPort) 2) en0: Ethernet 3) p2p0 default: What interface should the network bridge to? ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: bridged ==> default: Forwarding ports... 1 Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg| conïŹg.vm.box = "precise32" conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box" conïŹg.vm.network :public_network end
  • 58. 58 ➜ ~ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'precise32'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: test_default_1431012579630_44486 ==> default: Clearing any previously set network interfaces... ==> default: Available bridged network interfaces: 1) en1: Wi-Fi (AirPort) 2) en0: Ethernet 3) p2p0 default: What interface should the network bridge to? ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: bridged ==> default: Forwarding ports... 1 Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg| conïŹg.vm.box = "precise32" conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box" conïŹg.vm.network "public_network", :bridge => 'en1: Wi-‐Fi (AirPort)' end
  • 60. ==> default: Mounting shared folders... default: /vagrant => /Users/monkehworks/my_project Mount Management conïŹg.vm.synced_folder "htdocs/", "/var/www" ==> default: Mounting shared folders
 default: /var/www => /Users/monkehworks/my_project/htdocs default: /vagrant => /Users/monkehworks/my_project
  • 62. config.vm.hostname = "mymachine" config.vm.provider :virtualbox do |v| v.customize ["modifyvm", :id, '-‐chipset', 'ich9'] v.customize ["modifyvm", :id, "-‐natdnshostresolver1", "on"] v.customize ["modifyvm", :id, "-‐ioapic", "on"] v.customize ["modifyvm", :id, "-‐memory", 2048] v.customize ["modifyvm", :id, "-‐cpus", "4"] #v.gui = true end
  • 64. Add specific software Create configuration files Execute commands Create users Manage services Automatically executed on vagrant up
  • 65. Aim to have an exact (or as close as possible) copy of your production environment
  • 68. config.vm.provision :shell, :inline => "mount ‐t tmpfs ‐o size=50m,mode=0777 tmpfs /vagrant/ app/cache"
  • 69. # -*- mode: ruby -*- # vi: set ft=ruby : $script = <<SCRIPT echo I am provisioning... date > /etc/vagrant_provisioned_at SCRIPT VAGRANTFILE_API_VERSION = "2" Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg| conïŹg.vm.box = "precise32" conïŹg.vm.box_url = "http://ïŹles.vagrantup.com/precise32.box" conïŹg.vm.provision :shell, :inline $script end
  • 70. config.vm.provision "shell", path: "script.sh" config.vm.provision "shell", path: "https://example.com/provisioner.sh" External Scripts
  • 74. Written in Ruby Open source with enterprise revenue model Similar features Both have a standalone and server-side edition Supported by a large community Modularized components Use packages for software installs Use templating for custom files Filesystem methods and more
 Chef & Puppet
  • 75. Chef Puppet Modules Cookbooks Modules Actions Recipes Manifests Language Ruby extended with DSL DSL Running order Sequential “Random” Approach Define actions Define state Programming style Procedural “OO-esque”
  • 76. An Intro to Chef
  • 77. Download cookbooks - https://github.com/opscode-cookbooks Configure chef.cookbooks_path in Vagrantfile Add recipes using chef.add_recipe in Vagrantfile Configure attributes with chef.json Group custom actions in custom cookbook Using Chef Solo
  • 78. VagrantïŹle config.vm.provision :chef_solo do |chef| chef.cookbooks_path = "./tools/chef/cookbooks" chef.add_recipe "mysql::server" chef.json = { "mysql" => { "server_root_password" => "foo", "server_repl_password" => "foo", "server_debian_password" => "foo" } } end
  • 79. cookbook ├── README.md ├── attributes ├── definitions ├── files │ └── default ├── libraries ├── metadata.rb ├── providers ├── recipes │ └── default.rb ├── resources └── templates └── default
  • 80. default['mysql']['port'] = 3306 default['mysql']['nice'] = 0 case node['platform_family'] when 'debian' default['mysql']['server']['packages'] = %w[mysql-server] default['mysql']['service_name'] = 'mysql' default['mysql']['basedir'] = '/usr' default['mysql']['data_dir'] = '/var/lib/mysql' default['mysql']['root_group'] = 'root' default['mysql']['mysqladmin_bin'] = '/usr/bin/mysqladmin' default['mysql']['mysql_bin'] = '/usr/bin/mysql' default['mysql']['conf_dir'] = '/etc/mysql' default['mysql']['confd_dir'] = '/etc/mysql/conf.d' default['mysql']['socket'] = '/var/run/mysqld/mysqld.sock' default['mysql']['pid_file'] = '/var/run/mysqld/mysqld.pid' default['mysql']['old_passwords'] = 0 default['mysql']['grants_path'] = '/etc/mysql/grants.sql' MySQL Attributes
  • 81. ... group 'mysql' do action :create end user 'mysql' do comment 'MySQL Server' gid 'mysql' system true home node['mysql']['data_dir'] shell '/sbin/nologin' end node['mysql']['server']['packages'].each do |name| package name do action :install notifies :start, 'service[mysql]', :immediately end end ... MySQL Server Recipe
  • 82. [client] host user = localhost = debian-sys-maint password = <%= node['mysql']['server_debian_password'] %> socket = <%= node['mysql']['socket'] %> [mysql_upgrade] host = localhost user = debian‐sys-maint password = <%= node['mysql']['server_debian_password'] %> socket = <%= node['mysql']['socket'] %> basedir = /usr MySQL Template
  • 85. execute 'update apt' do command "apt‐get update" action :run end package 'mysql-server' do action :install notifies :start, 'service[mysql]', :immediately end package 'apache2' do action :install notifies :start, 'service[apache2]', :delayed end package 'php5' do action :install notifies :reload, 'service[apache2]', :delayed end ./tools/chef/cookbooks/project/recipes/default.rb
  • 86. execute 'assign‐root‐password' do command "/usr/bin/mysqladmin -u root password ‘#{node['project'] ['server_root_password']}'" action :run only_if "/usr/bin/mysql -u root -e 'show databases;'" end service 'mysql' do service_name 'mysql' supports :status => true, :restart => true, :reload => true action :enable end service 'apache2' do service_name 'apache2' supports :status => true, :restart => true, :reload => true action :enable end ./tools/chef/cookbooks/project/recipes/default.rb
  • 87. VagrantïŹle VAGRANTFILE_API_VERSION = "2" Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg| conïŹg.vm.box = "precise32" conïŹg.vm.box_url = “http://ïŹles.vagrantup.com/precise32.box" conïŹg.vm.synced_folder "htdocs/", "/var/www" conïŹg.vm.provision :chef_solo do |chef| chef.cookbooks_path = "./tools/chef/cookbooks" chef.add_recipe "project" chef.json = { "project" => { "server_root_password" => "foo" } } end end
  • 88. ➜ ~ vagrant up ... ==> default: Mounting shared folders
 default: /var/www => /Users/monkehworks/my_project/htdocs default: /vagrant => /Users/monkehworks/my_project ==> default: /tmp/vagrant-chef-1/chef-solo-1/cookbooks ==> default: Running provisioner: chef_solo
 Generating chef JSON and uploading
 Running chef-solo
 ...
  • 90. An Intro to Puppet
  • 91. Download modules - https://forge.puppetlabs.com Configure in Vagrantfile: - puppet.module_path - puppet.manifests_path - puppet.manifest_file Provisioning flow happens in the main manifest Configure attributes with puppet.facter Using Puppet Apply
  • 92. VagrantïŹle config.vm.provision :puppet do |puppet| puppet.manifests_path = "./tools/puppet/manifests" puppet.module_path = "./tools/puppet/modules" puppet.manifest_file = "init.pp" puppet.options = ['--verbose'] end init.pp include mysql::server class { '::mysql::server' :root_password => 'foo' }
  • 93. module ├── README.md ├── files ├── lib ├── metadata.json ├── spec ├── manifests │ └── init.pp │ └── params.pp ├── resources └── templates └── tests
  • 94. MySQL Params class mysql::params { $manage_config_file = true $old_root_password = '' $purge_conf_dir = false $restart = false $root_password = 'UNSET' $server_package_ensure = 'present' $server_service_manage = true $server_service_enabled = true # mysql::bindings $bindings_enable = false $java_package_ensure = 'present' $java_package_provider = undef $perl_package_ensure = 'present' $perl_package_provider = undef $php_package_ensure = 'present' $php_package_provider = undef $python_package_ensure = 'present' $python_package_provider = undef $ruby_package_ensure = 'present' $ruby_package_provider = undef
  • 95. MySQL server manifest class mysql::server ( $config_file = $mysql::params::config_file $manage_config_file = $mysql::params::manage_config_file $old_root_password = $mysql::params::old_root_password, $override_options = {}, $package_ensure = $mysql::params::server_package_ensure, $package_name = $mysql::params::server_package_name, $purge_conf_dir = $mysql::params::purge_conf_dir, $remove_default_accounts = false, $restart = $mysql::params::restart, $root_group = $mysql::params::root_group, $root_password = $mysql::params::root_password, $service_enabled = $mysql::params::server_service_enabled, $service_manage = $mysql::params::server_service_manage, $service_name = $mysql::params::server_service_name, $service_provider = $mysql::params::server_service_provider, # Deprecated parameters $enabled = undef, $manage_service = undef ) inherits mysql::params { ...
  • 96. [client] user=root host=localhost <% unless scope.lookupvar('mysql::server::root_password') == 'UNSET' ‐%> password='<%= scope.lookupvar('mysql::server::root_password') %>' <% end ‐%> socket=<%= @options['client']['socket'] ‐%> MySQL Template
  • 99. exec { "apt‐update": command => "/usr/bin/apt-get update", } package { 'mysql‐server': ensure => present, require => Exec['apt‐update'], notify => Service['mysql'], } package { 'apache2': ensure => present, require => Exec['apt‐update'], notify => Package['php5'], } package { 'php5': ensure => present, require => Exec['apt‐update'], notify => Service['apache2'], } ./tools/puppet/manifests/init.pp
  • 100. ./tools/puppet/manifests/init.pp exec {'assign‐root‐password': command => "/usr/bin/mysqladmin ‐u root password $root_password", require => Package["mysql‐server"], onlyif => "/usr/bin/mysql ‐u root ‐e 'show databases;'" } service { "mysql": name => "mysql", ensure => running, enable => true, hasrestart => true, require => Package["mysql‐server"], } service { "apache2": name => "apache2", ensure => running, enable => true, hasrestart => true, require => Package["apache2"], }
  • 101. VagrantïŹle VAGRANTFILE_API_VERSION = "2" Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg| conïŹg.vm.box = "precise32" conïŹg.vm.box_url = “http://ïŹles.vagrantup.com/precise32.box" conïŹg.vm.synced_folder "htdocs/", "/var/www" conïŹg.vm.provision :puppet do |puppet| puppet.manifests_path = "./tools/puppet/manifests" puppet.module_path = "./tools/puppet/modules" puppet.manifest_file = “init.pp" puppet.facter = { “root_password” => “foo”, } puppet.options = ['--verbose'] end end
  • 104. (when machine is running) ➜ ~ vagrant provision
  • 106. Provisioning is often slow Quality of public cookbooks/manifests Support on cookbooks/manifests Writing it yourself can be difficult Distribution restrictions
  • 107. ➜ ~ vagrant package
  • 108. Possible solution for slow provisioning Is not the same as vagrant box repackage Use exported box as new base box No provisioning required on startup Possibility of doing “light” provisioning instead
  • 111. VAGRANTFILE_API_VERSION = "2" Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg| conïŹg.vm.provision "shell", inline: "/usr/bin/apt‐get update" conïŹg.vm.box = "debian‐7.1.0" conïŹg.vm.deïŹne "web", primary: true do |web| web.vm.hostname = "web" web.vm.network :private_network, ip: "192.168.33.10" web.vm.synced_folder "htdocs/", "/var/www" web.vm.provision :puppet do |puppet| puppet.manifests_path = "./tools/puppet/manifests" puppet.module_path = "./tools/puppet/modules" puppet.manifest_ïŹle = "web.pp" puppet.options = ['-‐verbose'] end end conïŹg.vm.deïŹne "db" do |db| db.vm.hostname = "db" db.vm.network :private_network, ip: "192.168.33.11" db.vm.provision :puppet do |puppet| puppet.manifests_path = "./tools/puppet/manifests" puppet.module_path = "./tools/puppet/modules" puppet.manifest_ïŹle = "db.pp" puppet.options = ['-‐verbose'] puppet.facter = { "root_password" => "foo", } end end
  • 112. VAGRANTFILE_API_VERSION = "2" Vagrant.conïŹgure(VAGRANTFILE_API_VERSION) do |conïŹg| conïŹg.vm.provision "shell", inline: "/usr/bin/apt‐get update" conïŹg.vm.box = "debian‐7.1.0" conïŹg.vm.deïŹne "web", primary: true do |web| web.vm.hostname = "web" web.vm.network :private_network, ip: "192.168.33.10" web.vm.synced_folder "htdocs/", "/var/www" web.vm.provision :puppet do |puppet| puppet.manifests_path = "./tools/puppet/manifests" puppet.module_path = "./tools/puppet/modules" puppet.manifest_ïŹle = "web.pp" puppet.options = ['-‐verbose'] end end conïŹg.vm.deïŹne "db" do |db| db.vm.hostname = "db" db.vm.network :private_network, ip: "192.168.33.11" db.vm.provision :puppet do |puppet| puppet.manifests_path = "./tools/puppet/manifests" puppet.module_path = "./tools/puppet/modules" puppet.manifest_ïŹle = "db.pp" puppet.options = ['-‐verbose'] puppet.facter = { "root_password" => "foo", } end end
  • 115. ➜ ~ vagrant up ➜ ~ vagrant destroy ➜ ~ vagrant ssh ➜ ~ vagrant up web ➜ ~ vagrant ssh web ➜ ~ vagrant destroy web ➜ ~ vagrant up db ➜ ~ vagrant ssh db ➜ ~ vagrant destroy db