Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Geeky Academy Week 3 :: Vagrant + Puppet

Geeky Academy Week 3 :: Vagrant + Puppet
- Vagrant 101
- Vagrant 201
- Vagrant 301

Geeky Academy Week 3 :: Vagrant + Puppet

  1. 1. VAGRANT 3rd WEEK SATURDAY, JULY 06, 2013 – SUNDAY, JULY 07, 2013 GEEK ACADEMY 2013
  2. 2. INSTRUCTOR TEAM TAVEE SOMKIAT THAWATCHAI Tavee (Vee) Khunbida Somkiat (Pui) Puisungnuen Thawatchai (Boy) Jongsuwanpaisan Siam Chamnan Kit tavee@sprint3r.com Siam Chamnan Kit somkiat@sprint3r.com Siam Chamnan Kit thawatchai@sprint3r.com
  3. 3. What Vagrant ? o http://www.vagrantup.com/ o Based on VirtualBox and Ruby o Manage VM with Simple Command line o Run on o Windows o Linux o Mac OS
  4. 4. VAGRANT 101 GEEK ACADEMY 2013
  5. 5. Simple Command Line $ gem install vagrant $ vagrant box add base <box url> $ vagrant init $ vagrant up
  6. 6. Step 1 :: Installation with Ruby Gem $ gem install vagrant
  7. 7. Step 2 :: Add Base Box $ vagrant box add base http://files.vagrantup.com/precise32.box ……. [vagrant] Downloading withVagrant::Downloaders::File... [vagrant] Copying box to temporary location... [vagrant] Extracting box... [vagrant]Verifying box... [vagrant] Cleaning up downloaded box...
  8. 8. Step 2.1 :: Where is my box ? o http://www.vagrantbox.es/
  9. 9. Step 3 :: Configuration $ 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 theVagrantfile as well as documentation on `vagrantup.com` for more information on usingVagrant.
  10. 10. Vagrantfile Vagrant::Config.run do |config| config.vm.box = "base“ end
  11. 11. Step 4 :: Boot $ vagrant up …. [default] Importing base box 'base'... [default] Matching MAC address for NAT networking... [default] Clearing any previously set forwarded ports... [default] Fixed port collision for 22 => 2222. Now on port 2200. [default] Forwarding ports... [default] -- 22 => 2200 (adapter 1) [default] Creating shared folders metadata... [default] Clearing any previously set network interfaces... [default] BootingVM... [default] Waiting forVM to boot.This can take a few minutes.
  12. 12. Ready to SSH User=vagrant Password=vagrant
  13. 13. Optional Command $ vagrant status $ vagrant halt $ vagrant destroy $ vagrant reload $ vagrant provision $ vagrant suspend $ vagrant resume
  14. 14. Summary for 101 o Reduce setup time o Simple o Self-service o Consistency o Repeat
  15. 15. VAGRANT 201 GEEK ACADEMY 2013 https://github.com/up1/geeky_devops
  16. 16. Working with Vagrantfile o Specified base box o Network Configuration o Sharing Folder o MultipleVM
  17. 17. Specified Base Box Vagrant::Config.run do |config| config.vm.box = "lucid32“ config.vm.box_url = "http://files.vagrantup.com/lucid32.box" config.vm.box_url = "c:demo-geekylucid32.box" end
  18. 18. Network Configuration Vagrant::Config.run do |config| config.vm.network :hostonly, "33.33.33.10" end
  19. 19. Sharing Folder Vagrant::Config.run do |config| config.vm.share_folder "foo", "/guest/path", "/host/path" end Path on VM Path on Local
  20. 20. Sharing Folder Vagrant::Config.run do |config| config.vm.share_folder "work", "/var/www", "./webapp” end
  21. 21. Multiple VM in Stack o Web Server o Application Server o Database Server o Caching Server o Messaging Server
  22. 22. Web Server and DB Server Vagrant::Config.run do |config| config.vm.define :web do |web_config| web_config.vm.host_name = "web01.internal" web_config.vm.network :hostonly, "192.168.0.100" end config.vm.define :db do |db_config| db_config.vm.host_name = "db01.internal" db_config.vm.network :hostonly, "192.168.0.101" end end
  23. 23. DEMO MORE o Flexible configuration o # of Server o Hostname o Manage IP
  24. 24. DEMO MORE o Web Server o web-01.vagrant.internal 33.33.33.11 o web-02.vagrant.internal 33.33.33.12 o DB Server o db-01.vagrant.internal 33.33.33.21
  25. 25. Servers nodes = { 'web' => [2, 10], 'db' => [1, 20], }
  26. 26. Create Servers nodes.each do |prefix, (count, ip_start)| count.times do |i| hostname = "%s-%02d" % [prefix, (i+1)] config.vm.define "#{hostname}" do |box| box.vm.host_name = "#{hostname}.vagrant.internal" box.vm.network :hostonly, "33.33.33.#{ip_start+i}“ end end end
  27. 27. VAGRANT 301 GEEK ACADEMY 2013
  28. 28. Vagrant with Puppet o https://puppetlabs.com o Configuration management with Code o Ruby o Repeatable
  29. 29. Demo :: Install all in one o Manage package with Puppet o Java o Apache Tomcat o Redis o RabbitMQ https://github.com/up1/geeky_devops demo-puppet
  30. 30. Structure of Puppet o puppet o manifests/default.pp o modules o java o manifests/init.pp o tomcat o manifests/init.pp o redis o manifests/init.pp o rabbitMQ o manifests/init.pp Starting point
  31. 31. Vagrantfile config.vm.provision :puppet do |puppet| puppet.manifests_path = "puppet/manifests" puppet.manifest_file = "default.pp" puppet.module_path = "puppet/modules" end Vagrant provision Starting point
  32. 32. Default.pp include bootstrap include redis include java include tomcat include rabbitmq Step to execute modules
  33. 33. Structure of Puppet o puppet o manifests/default.pp o modules o java o manifests/init.pp o tomcat o manifests/init.pp o redis o manifests/init.pp o rabbitMQ o manifests/init.pp Starting point each module
  34. 34. Init.pp :: Java class java { package { "openjdk-7-jdk": ensure => installed, require => Exec['apt-get update'] } }
  35. 35. Init.pp :: Package Apache Tomcat class tomcat { package { "tomcat6": ensure => installed, require => Package['openjdk-7-jdk'], } package { "tomcat6-admin": ensure => installed, require => Package['tomcat6'], } }
  36. 36. Init.pp :: Service Apache Tomcat class tomcat { service { "tomcat6": ensure => running, require => Package['tomcat6'], subscribe => File["tomcat-users.xml"] } }
  37. 37. Init.pp :: Tomcat-users.xml class tomcat { file { "tomcat-users.xml": owner => 'root', path => '/etc/tomcat6/tomcat-users.xml', require => Package['tomcat6'], notify => Service['tomcat6'], content => template( '/path/tomcat/templates/tomcat- users.xml.erb') } }
  38. 38. Tomcat-users.xml.erb <?xml version='1.0' encoding='utf-8'?> <tomcat-users> <role rolename="manager"/> <role rolename="admin"/> <user name="tomcat-admin" password="12345" roles="manager,admin"/> </tomcat-users>
  39. 39. More Demo o https://github.com/up1/geeky_devops o demo-multi-puppet box.vm.provision :puppet do |puppet| puppet.manifests_path = "puppet/manifests" puppet.manifest_file = "#{prefix}.pp" puppet.module_path = "puppet/modules" end
  40. 40. Question ?
  41. 41. GEEK ACADEMY 2013
  42. 42. THANK YOU FOR YOUR TIME GEEK ACADEMY 2013

×