Config managament for development environments iii
1. Configuration Management
for Development Environments
PuppetConf 22nd September 2011
gareth rushgrove | morethanseven.net http://www.flickr.com/photos/36144637@N00/159627088/
7. 1. Not all developers want to be sysadmins
gareth rushgrove | morethanseven.net http://www.flickr.com/photos/34652102@N04/5059217055
8. 1. Sysadmins don’t want devs to be sysadmins
gareth rushgrove | morethanseven.net http://www.flickr.com/photos/34652102@N04/5059217055
9. 2. New team members getting started time
gareth rushgrove | morethanseven.net http://www.flickr.com/photos/34652102@N04/5059824808
10. 3. Running a full set of services locally
gareth rushgrove | morethanseven.net http://www.flickr.com/photos/biggreymare
11. 4. Works on my machine
gareth rushgrove | morethanseven.net
12. ⚡ brew info mysql
mysql 5.5.14
$ aptitude show mysql-server
Package: mysql-server
State: not installed
Version: 5.1.41-3ubuntu12.10
Homebrew is great but...
gareth rushgrove | morethanseven.net
13. 23 releases and 21 months in-between 5.1.41 and 5.5.14. Here’s
some fixed bugs:
- An ORDER BY clause was bound to the incorrect substatement
when used in UNION context.
- A NOT IN predicate with a subquery containing a HAVING clause
could retrieve too many rows, when the subquery itself returned
NULL.
- MIN(year_col) could return an incorrect result in some cases.
And lots more
What’s a few versions between friends?
gareth rushgrove | morethanseven.net
14. Spot the cross platform bug (not the security flaw)
gareth rushgrove | morethanseven.net
15. ⚡ ./server.rb &
⚡ curl "http://127.0.0.1:8181/?query=Bob"
⚡ curl "http://127.0.0.1:8181/?query=bob"
⚡ ls
On our Mac
gareth rushgrove | morethanseven.net
16. ⚡ ./server.rb &
⚡ curl "http://127.0.0.1:8181/?query=Bob"
⚡ curl "http://127.0.0.1:8181/?query=bob"
⚡ ls
Bob
⚡ cat Bob
Hello bob
On our Mac
gareth rushgrove | morethanseven.net
17. $ ./server.rb &
$ curl "http://127.0.0.1:8181/?query=Bob"
$ curl "http://127.0.0.1:8181/?query=bob"
$ ls
On Linux
gareth rushgrove | morethanseven.net
18. $ ./server.rb &
$ curl "http://127.0.0.1:8181/?query=Bob"
$ curl "http://127.0.0.1:8181/?query=bob"
$ ls
Bob bob
$ cat Bob
Hello Bob
$ cat bob
Hello bob
On Linux
gareth rushgrove | morethanseven.net
29. - Automated virtual machine creation using Oracle’s VirtualBox
- Automated provisioning of virtual environments using Chef or Puppet
- Full SSH access to created environments
- Assign a static IP to your VM, accessible from your machine
- Forward ports to the host machine
- Shared folders allows you to continue using your own editor
- Package environments into distributable boxes
- Completely tear down environment when you’re done
- Easily rebuild a complete environment with a single command
What is Vagrant?
gareth rushgrove | morethanseven.net
37. Vagrant::Config.run do |config|
config.vm.forward_port("web", 80, 8080)
config.vm.forward_port("ftp", 21, 4567)
config.vm.forward_port("ssh", 22, 2222, :auto => true)
end
Port forwarding
gareth rushgrove | morethanseven.net
38. Vagrant::Config.run do |config|
config.vm.share_folder("folder", "/guest", "../host")
end
Shared folders
gareth rushgrove | morethanseven.net
39. Vagrant::Config.run do |config|
config.vm.define :web do |web_config|
web_config.vm.box = "web"
web_config.vm.forward_port("http", 80, 8080)
end
config.vm.define :db do |db_config|
db_config.vm.box = "db"
db_config.vm.forward_port("db", 3306, 3306)
end
end
Multiple VMs in one file
gareth rushgrove | morethanseven.net
40. Vagrant::Config.run do |config|
config.vm.boot_mode = :gui
config.ssh.forward_agent = true
config.vm.network("33.33.33.10")
config.vm.customize do |vm|
vm.memory_size = 512
end
end
Lots more options
gareth rushgrove | morethanseven.net
42. Vagrant::Config.run do |config|
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "puppetmanifests"
puppet.manifest_file = "newbox.pp"
end
end
Vagrant provisioning with Puppet
gareth rushgrove | morethanseven.net
43. Vagrant::Config.run do |config|
config.vm.provision :puppet_server do |puppet|
puppet.puppet_server = "puppet.example.com"
puppet.puppet_node = "vm.example.com"
end
end
Vagrant provisioning with Puppetmaster
gareth rushgrove | morethanseven.net
45. Vagrant::Config.run do |config|
config.vm.provision :chef_solo do |chef|
chef.add_recipe = "garethr"
chef.cookbooks_path = “cookbooks”
end
end
Vagrant provisioning with Chef
gareth rushgrove | morethanseven.net
46. Vagrant::Config.run do |config|
config.vm.provision :chef_solo do |chef|
chef.roles_path = "roles"
chef.add_role("vm")
end
end
Specifying Chef roles
gareth rushgrove | morethanseven.net
47. Vagrant::Config.run do |config|
config.vm.provision :chef_solo do |chef|
chef.recipe_url = "http://github.com/cookbooks.tar.gz"
chef.add_recipe "garethr"
chef.cookbooks_path = [:vm, "cookbooks"]
chef.json.merge!({ :garethr => {
:ohmyzsh => "https://github.com/.../oh-my-zsh.git",
:dotvim => "https://github.com/garethr/dotvim.git"
}})
end
end
Remote file
gareth rushgrove | morethanseven.net
50. Useful for local configuration management
gareth rushgrove | morethanseven.net http://www.flickr.com/photos/crustyscumbrothersontour/2674351601
51. - I want my development environment on my local vms
- I don’t want a wiki page of instructions
- I don’t want to have to manually install anything
- I don’t want to care about destroying a virtual machine
Real world example
gareth rushgrove | morethanseven.net
56. require 'spec_helper'
describe 'ohmyzsh', :type => :class do
it { should create_exec("ohmyzsh") }
it { should create_exec("zshrc") }
it { should create_class("base") }
end
Testing with Rspec
gareth rushgrove | morethanseven.net
57. base
should create Package[zsh]
should create Package[vim-nox]
should create Package[git-core]
ohmyzsh
should create Exec[ohmyzsh]
should create Exec[zshrc]
should create Class[base]
Finished in 1.4 seconds
10 examples, 0 failures
Rspec results
gareth rushgrove | morethanseven.net
58. - Using Virtualisation makes getting started fast
- Running the same platform catches bugs early
- Using Vagrant makes managing virtual machines easy
- Writing configuration as code makes it testable
Conclusions
gareth rushgrove | morethanseven.net
59. - IRC - #vagrant on Freenode
- Github Issues - https://github.com/mitchellh/vagrant/issues
- Google Groups - http://groups.google.com/group/vagrant-up
More information on Vagrant
gareth rushgrove | morethanseven.net