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.

Using Puppet on Linux, Windows, and Mac OSX

6,372 views

Published on

Hein Couwet's presentation "Using Puppet on Linux, Windows, and Mac OSX" from Puppet Camp Ghent 2013.

Published in: Technology
  • Dating for everyone is here: ❤❤❤ http://bit.ly/2F4cEJi ❤❤❤
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Sex in your area is here: ❶❶❶ http://bit.ly/2F4cEJi ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Using Puppet on Linux, Windows, and Mac OSX

  1. 1. Using puppet on Linux, Windows and Mac OSXHein Couwet2improveIThein@2improveit.eu@heincouwet
  2. 2. Lessons learned frominstalling a development stack on the 3 major operating systems : Linux, Mac OSX and Windows.
  3. 3. Context
  4. 4. installing a development stack @iDalko• automated• asap : < 15 minutes
  5. 5. Installing an integrated stack• Atlassian tools (JIRA/Confluence/Fisheye/ Crucible/Bamboo/Stash)• Other OpenSource Tools : Sonar / BIRT/ Nexus• Database MySQL• Frontend : Apache
  6. 6. Choice between• Puppet• Chef• scripting : ant / bash / ...
  7. 7. Why Puppet• Declarative syntax• No ‘programming’ skills ...• so the customer can understand without learning a new language
  8. 8. Example : Nexus
  9. 9. Episode I : Ubuntu
  10. 10. Platform : Ubuntu• Downloading using wget• uncompress using tar -zxf• starting up using linux services• installing packages mysql and apache• configuring vproxy in apache
  11. 11. Download define download($url,$location,$filename) { exec { "download-$filename": cwd => "$location", command => "/usr/bin/wget $url", creates => "$location/$filename", logoutput => "on_failure", timeout => 0, require => File["$location"], } }
  12. 12. Uncompress define untargz($location,$filename,$creates) { exec { "untargz": cwd => "$location", command => "/bin/tar -zxvf $filename", creates => "$creates", logoutput => "on_failure", timeout => 0, } }
  13. 13. Starting up linux servicesfile { "/etc/init.d/nexus": ensure => link, target => "${nexus_install}/bin/nexus", }service { "nexus": ensure => running, require => File["/etc/init.d/nexus"], }
  14. 14. Installing packages Apache package { "apache2-mpm-prefork": ensure =>installed } service { "apache2": enable => true, ensure => running, require => Package["apache2-mpm-prefork"], }
  15. 15. Lessons learned ...• instead of using a { “xxx”: ... } b { “yyy” : .... require => A[“xxx”] }
  16. 16. Lessons learned ...• start using a { “xxx”: ... } -> b { “yyy” : .... }
  17. 17. Episode II : CentOS
  18. 18. Challenge 1• Another customer has a CentOS server instead of Ubuntu ...• can we also use puppet ?
  19. 19. Problem 1• other naming of apache packages • apache2 <-> httpd
  20. 20. Solution case    $operatingsystem  {          "CentOS":    {                $packages  =  [  "httpd"  ]                package  {  $packages:                                    ensure  =>  installed,                }                service  {  "httpd":                                ensure  =>  running,                                require  =>  Package["httpd"],                }            }            "Debian":  {                $packages  =  [  "apache2-­‐mpm-­‐prefork"  ]                package  {  $packages:                                    ensure  =>  installed,                }                  service  {  "apache2":                                ensure  =>  running,                                require  =>  Package["apache2-­‐mpm-­‐prefork"]                }        }
  21. 21. Opportunity 1• start using hiera
  22. 22. Episode III : OSX
  23. 23. Why ?• Just for local testing on my development machine• ➟ limited scope, no longer apache, service ...
  24. 24. small adaptations ...• instead of exec { ...: command => "/usr/bin/wget $url", }• now use exec { ... : command => "wget $url", path => “$::path”, }
  25. 25. Episode IV : Windows
  26. 26. Windows• Back to basics• no longer ‘standard’ commands• no longer unix paths• limited set of puppet resources available
  27. 27. Window Paths Windows file paths must be written in different ways at different times, due to various tools’ conflicting rules for backslash use.1 Windows file system APIs accept both the backslash () and forwardslash (/) to separate directory and file components in a path.2 Some Windows programs only accept backslashes in file paths.3 *nix shells and many programming languages — including the Puppet language — use the backslash as an escape character.As a result, any system that interacts with *nix and Windows systems as equal peers will unavoidably have complicated behavior around backslashes.The following guidelines will help you use backslashes safely in Windows file paths with Puppet.Forward Slashes vs. BackslashesIn many cases, you can use forward slashes instead of backslashes when specifying file paths.Forward slashes MUST be used in:1 Template paths passed to the template function. For example:    file  {C:/warning.txt:2        ensure    =>  present,3        content  =>  template(my_module/warning.erb),4    }6 Puppet URLs in a file resource’s source attribute.
  28. 28. Window Paths Forward slashes SHOULD be used in: 1 The title or path attribute of a file resource 2 The source attribute of a package resource 3 Local paths in a file resource’s source attribute 4 The command of an exec resource, unless the executable requires backslashes, e.g. cmd.exeForward slashes MUST NOT be used in: 1 The command of a scheduled_task resource. 2 The install_options of a package resource.The RuleIf Puppet itself is interpreting the file path, forward slashes are okay. If the file path is being passed directly to a Windows program, forward slashes may not be okay.Using Backslashes in Double-Quoted StringsPuppet supports two kinds of string quoting. Strings surrounded by double quotes (") allow variable interpretation and many escape sequences (including the commonn for a newline), so care must be taken to prevent backslashes from being mistaken for escape sequences.When using backslashes in a double-quoted string, you must always use two backslashes for each literal backslash. There are no exceptions and no special cases.Using Backslashes in Single-Quoted StringsStrings surrounded by single quotes () do not allow variable interpretation, and the only escape sequences permitted are (a literal single quote) and (a literalbackslash).Lone backslashes can usually be used in single-quoted strings. However: 1 When a backslash occurs at the very end of a single-quoted string, a double backslash must be used instead of a single backslash. For example: path  =>  C: Program  Files(x86)
  29. 29. Window Paths The RuleIf Puppet itself is interpreting the file path, forward slashes are okay. If the file path is being passed directly to a Windows program, forwardslashes may not be okay.Using Backslashes in Double-Quoted StringsPuppet supports two kinds of string quoting. Strings surrounded by double quotes (") allow variable interpretation and many escapesequences (including the common n for a newline), so care must be taken to prevent backslashes from being mistaken for escapesequences.When using backslashes in a double-quoted string, you must always use two backslashes for each literal backslash. There are noexceptions and no special cases.Using Backslashes in Single-Quoted StringsStrings surrounded by single quotes () do not allow variable interpretation, and the only escape sequences permitted are (a literalsingle quote) and (a literal backslash).Lone backslashes can usually be used in single-quoted strings. However: 1 When a backslash occurs at the very end of a single-quoted string, a double backslash must be used instead of a single backslash. For example: path  =>  C:Program  Files(x86) 2 When a literal double backslash is intended, a quadruple backslash must be used.The RuleIn single-quoted strings: 1 A double backslash always means a literal backslash. 2 A single backslash usually means a literal backslash, unless it is followed by a single quote or another backslash.
  30. 30. Conclusion: Paths on Windows• I don’t even want to show you my first attempt• Too complicated !!!!
  31. 31. Basic tools doesn’t exist• tar• unzip• wget
  32. 32. Ruby to the rescue• Puppet providers /resources • creating new ones • replacing wget • replacing tar / unzip • programming in Ruby, but still understandable for the customer
  33. 33. puppet/type/install.rb Puppet::Type.newtype(:install) do ensurable newparam (:path) do desc "The file name where to install" end newparam(:uri) do! desc "The uri from where to get the file" isnamevar validate do |value| if value =~ /^http:/ resource[:provider] = :http end end end newparam(:download) do! desc "The intermediary file as download" end newparam(:unzip) do desc "Need to unzip" endend
  34. 34. puppet/provider/install/ http.rb require fileutilsrequire net/httprequire urirequire zip/zipPuppet::Type.type(:install).provide(:http) do def create path = resource[:path] if resource[:download] temp_path = resource[:download] else temp_path = "#{path}.download" end uri = URI(resource[:uri]) download( uri, temp_path) if resource[:unzip] unzip_file(temp_path,path) else FileUtils.mv temp_path path end! FileUtils.touch "#{temp_path}.done" end def exists? path = resource[:path] if resource[:download] temp_path = resource[:download] else temp_path = "#{path}.download" end! check_path = "#{temp_path}.done"! File.exist? check_path end def unzip_file (file, destination) end def download (uri , path)end end
  35. 35. Pitfalls• Use the correct gem • not zip • buggy ... :-( • but rubyzip
  36. 36. Pitfalls• Augeas • not supporting xml with mixed quotes • not yet supported on puppet - windows
  37. 37. Ruby to the rescue• adding providers for • text replacement • xml-path replacement
  38. 38. My Conclusion• Never use exec• Core Puppet needs some basic functionality support for ALL platforms such as • downloading files from the web : wget • zip / tar • search/replace in file/xml ...
  39. 39. My PuppetOpportunities for 2013• hiera• Testing my puppet scripts
  40. 40. Questions ?

×