environments line-up! vagrant & puppet 101
TRANSCRIPT
VAGRANT & PUPPET 101
ENVIRONMENTS, LINE UP!
ME
• Jelrik van Hal
• Ingewikkeld
• @jelrikvh
MY MESSAGE
ETCETERA, ETCETERA
(random code; don’t read it)
INSTALLATION
$ cd project$ vagrant init
(www.vagrantbox.es)
http://someurl.to/wheezy64.boxwheezy64
$ vagrant init wheezy64 http://someurl.to/wheezy64.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.
Vagrant.configure("2") do |config| config.vm.box = "wheezy64" config.vm.box_url = "http://someurl.to/wheezy64.box" config.vm.network :forwarded_port, guest: 80, host: 8080 config.vm.network :private_network, ip: "192.168.42.42" config.vm.synced_folder ".", "/vagrant"end
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...[default] Box 'wheezy64' was not found. Fetching box from specified URL for the provider 'virtualbox'. Note that if the URL does not have a box for this provider, you should interrupt Vagrant now and add the box yourself. Otherwise Vagrant will attempt to download the full box prior to discovering this error.Downloading or copying the box...Extracting boxSuccessfully added box 'wheezy64' with provider 'virtualbox'!
$ vagrant up
[default] Importing base box 'wheezy64'...[default] Matching MAC address for NAT networking...[default] Setting the name of the VM...[default] Clearing any previously set forwarded ports...[default] Creating shared folders metadata...[default] Clearing any previously set network interfaces...[default] Preparing network interfaces based on configuration...[default] Forwarding ports...[default] -- 22 => 2222 (adapter 1)[default] -- 80 => 8080 (adapter 1)[default] Booting VM...[default] Waiting for VM to boot. This can take a few minutes.[default] VM booted and ready for use![default] Configuring and enabling network interfaces...[default] Mounting shared folders...[default] -- /vagrant
$ vagrant ssh
$ vagrant halt
$ vagrant reload
$ vagrant up
$ vagrant destroy
$
$
$ mkdir –p puppet/manifests
$ touch puppet/manifests/basenode.pp
# Vagrantfileconfig.vm.provision :puppet do |puppet| puppet.manifests_path = "puppet/manifests" puppet.manifest_file = "basenode.pp"end
# puppet/manifests/basenode.ppExec { path => [ '/bin/', '/sbin/' , '/usr/bin/’ ],} package { 'php5': ensure => present,} package { 'mysql-server': ensure => present,} package { 'apache2': ensure => present,}
# puppet/manifests/basenode.pp
(...)
package { 'apache2': ensure => present,}
# puppet/manifests/basenode.pp
(...)
file { "configure_vhost": ensure => present, path => "/path/to/apache/config/folder", owner => ‘root', group => ‘root', mode => '0600', source => 'puppet:///files/vhost_template’, replace => false}
# puppet/manifests/basenode.pp
(...)
file { "configure_vhost": ensure => present, path => "/path/to/apache/config/folder", owner => ‘root', group => ‘root', mode => '0600', source => 'puppet:///files/vhost_template’, replace => false, require => Package["apache2"], notify => Service[“apache2”]}
THE WAY TO GO?
I wouldn’t say so.
There is too much we need to know.
PLUG AND PLAY MODULES
https://github.com/example42
http://forge.puppetlabs.com
…
# Vagrantfileconfig.vm.provision :puppet do |puppet| puppet.manifests_path = "puppet/manifests" puppet.modules_path = "puppet/modules" puppet.manifest_file = "basenode.pp"end
$ ls puppet/modules/apache/
Modulefile README.md Rakefile manifests spec templates
# puppet/manifests/basenode.pp
(...)
class { "apache": }
apache::vhost { 'default': docroot => '/var/www/document_root', server_name => ‘dev.example.org’, priority => '', template => 'apache/virtualhost/vhost.conf.erb',}
$ vagrant up
$ vagrant up --provision
$ vagrant provision
SO, WHY VAGRANT?
• No more “works on my machine”
• The right software, and nothing more
• Clean development machine
• Power of provisioning
WHAT’S MORE?
• Multiple machines
• On Windows
• Please note: Vagrant 1.2 -> 1.3
@skoop @jelrikvh @mvriel
http://www.vagrantup.com/ http://www.vagrantbox.es/https://github.com/example42?tab=repositories
http://forge.puppetlabs.com/
@jelrikvh
THANKS!