Getting started with Puppet

Download Getting started with Puppet

Post on 10-May-2015

8.320 views

Category:

Technology

2 download

TRANSCRIPT

1.Getting started with PuppetJeremy MATHEVET12/09/20122. TopicsConfiguration managementPuppet InstallationPuppetmasterPuppet language basicsPuppet language advanced 3. Configuration managementPuppet, Chef, Cfengine 4. Configuration management Definition Configuration Management is the process of standardizing resource configurations and enforcing their state across IT infrastructure in an automated yet agile manner. Puppet Labs 5. Configuration management Why do we need it Heterogeneous Operating Systems Servers profusion Increasing deployment needsCloud 6. Configuration managementDifferent solutions3 ways for deploying software to the SIManuallyCould take very long timeBy scriptsCould be quite tricky Multi-environment caseBy configuration management software 7. Configuration managementConfiguration management softwarePros :Centralized managementAutomated managementMass deploymentConfiguration customizationAbstraction layerIdempotenceDevOps ready 8. Configuration managementPrinciple A client/serverarchitecture. The server has a reference configuration. The client queries the server. The client makes change in order to match the reference configuration. 9. Configuration managementPrinciple 1. Pull Request 2. Reference configuration 3. Operations 4. (optionnal) Message code / error 10. Configuration managementPrincipleVersion control and security Revision control used to keep a trace of config revisionsNot mandatory but hugely recommended Encrypted connection 11. Configuration management Principle What you can do File transfer File edition Service management Package management Mount points management Cron management VLAN management Command launching 12. Configuration managementComparison 3 major solutions : PuppetThe most popularEasiest solution ChefPuppet forkStill young but very promising CFEngineThe first CM softwareThe most resource effectiveMore complex 13. Configuration management ComparisonTimeline : 14. Configuration management ComparisonSome differences Technology Ruby RubyCConfiguration DedicatedRuby Dedicatedlangage langageConfigurationPlain text filesmethodPlain text filesCLI toolPlain text filesWeb UI Licence Apache Apache GPL 15. Configuration managementComparison Some similarities Same origin Specially designed for configmanagement Client/server modelStandalone mode possible CLI interface Need to increase yourcompetence 16. Configuration management Do you have any questions ? 17. Puppet Installation Install && setup 18. Puppet Installation PuppetSome details and features Created in 2006 by Puppet Labs Latest version : 3.0.0 The easiest solution Dedicated declarative languageInspired by Ruby Modular configuration System profiling with Facter Template support Asymmetric Key Encryption 19. Puppet Installation PuppetPrerequisite and sources PrerequisiteConfigured DNSRuby Installation sources :Distribution repositoriesRubyGemSources 20. Puppet InstallationPuppetClient and server Puppet server : Puppetmaster Puppet client : Puppet (agent) Main steps once installed :Puppet agent installation on client hosts (also called a node). Enter the server FQDN into /etc/puppet/puppet.conf The agent checks every 30 mn by defaultCertificate generation CSR for the node generated on the puppetmaster during the first agent request 21. Puppet InstallationWorking with Puppetmaster Working with Puppet CA[root@puppetmaster ~]# puppetca --sign fqdn.utopia.netOptionsDefinitions--signSign the certificate request for the following host--listList certificate request--all Used with --sign, sign all certificate request--clean Remove all files related to the host from the CA--print Print the full text version of a hosts certificate--revokeRemove all files related to the host from the CA 22. Puppet InstallationDo you have any questions ? 23. Puppet Puppetmaster Puppetmaster said 24. Puppetmaster One important thing Infrastructure is code. 25. PuppetmasterDefinition Manifest Puppet programs are called manifests . They use the .pp file extension. These programs contain one or more class. 26. Puppetmaster Puppet configuration tree Configuration files overview 1/2 puppet.conf General Puppetmaster settings auth.conf General ACL fileserver.conf ACL for the Puppet fileserver manifests directory site.pp : global defaultsconfiguration nodes.pp : manage hosts 27. Puppetmaster Puppet configuration tree Configuration files overview 2/2 modules directory Contain one subdirectory per module manifests/init.pp The module code The best way to use Puppet templates directory The default directory which contains templates. 28. PuppetmasterPuppet configuration files puppet.conf [main] logdir=/var/log/puppet vardir=/var/lib/puppet ssldir=/var/lib/puppet/ssl rundir=/var/run/puppet factpath=$vardir/lib/facter templatedir=$confdir/templates server=debiantest.decilex.net downcasefacts = true 29. PuppetmasterPuppet configuration files manifests/nodes.pp Skeleton : node basenode { node fqdn { include include ssh module} include ntp } Node declaration node test.utopia.net inherits basenode { Module inclusioninclude nagios Inheritance } 30. Puppetmaster Puppet configuration files Reading ordermanifests/site.pp manifests/nodes.pp modules/$nomdumodule/manifests/init.pp modules/$nomdumodule/files/ 31. Puppetmaster Do you have any questions ? 32. Puppet Puppet language basicsPuppet, Chef, Cfengine 33. Puppet language basics The declarative languageAbout the language With Puppet, we declare how the node must be. Everything you want to manage have to be explicitly declared. A Puppet program is called a manifest Central manifest : site.pp Puppet load modules manifests Into manifests, we define classes.We write resources inside theseclasses 34. Puppet language basics The declarative languageResources The fundamental unit of modeling Like a function Inside, a series of attributes and their values Resources types and attributes are predefined by Puppet List of available resources http://docs.puppetlabs.com/references/stable/type.html SkeletonRessource-name { title : attribute = value } 35. Puppet language basics ResourcesFile Manage filesfile { /etc/passwd: Content owner => root, group => root, Permissions mode => 0644, Ownership source => puppet:///base/passwd } Source attribute Copy a file from the Puppetmaster to the node puppet:/// followed by the relative source of the file placed in /etc/puppet/modules/module-name/files/ 36. Puppet language basicsResourcesPackagepackage { openssh-server:ensure => installed } Manage packages Wide provider support package { openssh-server:ensure => latest APT } Aptitudepackage { openssh-server: YUMensure => absent } And more.. Install, upgrade, uninstall packages The last or defined package version 37. Puppet language basics ResourcesService Manage services Wide provider supportservice { snmpd: Init ensure => running,enable => true, Systemdhasrestart => true, Upstarthasstatus => true} And more Start, stop, restart, start on boot (enable) services 38. Puppet language basics Do you have any questions ? 39. Puppet Puppet language advanced Dive into Puppet 40. Puppet language advanced Facter The system profiler Software used by Puppet ~ # facterarchitecture => i386 Installed on nodesdomain => utopia.netfacterversion => 1.5.7 Collect various data, "facts",fqdn => debiantest.utopia.neton node hardwaremodel => i686 Many facts already defined by hostname => debiantestFacterid => root[] Possibility to create your own facts 41. Puppet language advancedVariables Variables into classes Begin by $ case $operatingsystem { Can use facts or you centos, redhat: { $service_name = ntpd }own defineddebian, ubuntu: { $service_name = ntp }variables} Often used withservice { ntp: conditionalname => $service_name, statements ensure => running,enable => true Case statement} If statement 42. Puppet language advancedConditional statements If/Elsif/Else Statementif $variable { file { /some/file: ensure => present } } else { Based on file { /some/other/file: ensure => present } } the truth valueof a variable the value of anexpressionif $server == mongrel { include mongrel The truth of an } elsif $server == nginx { arithmeticinclude nginx expression} else { include thin }if $ram > 1024 { $maxclient = 500 } 43. Puppet language advancedExpressions Operators Operators usable in if statements Boolean expressionsAnd, or, not Comparison expressions== =! < > >= Arithmetic expressions+ - / * >> (left shift) "/etc/hosts",personalizedowner => root,configuration per nodegroup => root,mode => 644, Use ERB language content => template("base/hosts.erb") Retrieve and use} facts Use file resource ERB file placed in module template directory 45. Puppet language advancedResources relationship Relationship meta-parameters before Resource is applied before the target resource require Resource is applied after the target resource notify Like before + The target resource will refresh if the notifying resource changes subscribe Like require + The subscribing resource will refresh if the target resource changes. 46. Puppet language advancedResources relationship Ordering relationship package { openssh-server: ensure => present, before => File[/etc/ssh/sshd_config], } file { /etc/ssh/sshd_config:ensure => file,mode => 600,source => puppet:///modules/sshd/sshd_config,require => Package[openssh-server],}These two examples are mutually-exclusive 47. Puppet language advanced Resources relationship Notification relationship file { /etc/ssh/sshd_config:ensure => file,mode => 600,source => puppet:///modules/sshd/sshd_config,notify => Service[sshd]} service { sshd: ensure => running, enable => true, subscribe => File[/etc/ssh/sshd_config] }These two examples are mutually-exclusive 48. Puppet language advanced Resources relationship Chaining and refreshing Ordering resources The resource on the left is applied before the resource on the right. -> Refreshing Kind of trigger Restart a service after a file update ~> # ntp.conf is applied first, and will notify the ntpd service if it changes: File[/etc/ntp.conf] ~> Service[ntpd] 49. Puppet language advanced Do you have any questions ? 50. PuppetSummary Configuration Configuration Puppetmaster Puppetmaster managementmanagement Puppet installation Puppet installationPuppet LanguagePuppet LanguagePuppet languagePuppet languageadvanced advancedbasicsbasics 51. ContactJeremy MATHEVET @JeygContent under Creative Commons BY 3.0 License

Recommended

View more >