More Related Content Similar to PuppetConf 2016 Moving from Exec to Types and Provides (20) More from Martin Alfke (15) PuppetConf 2016 Moving from Exec to Types and Provides2. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
example42 GmbH - Berlin / Germany
Martin Alfke
CEO & Co-Founder
2
4. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Puppet Module for VM management system
4
OpenNebula config concept - Image taken from opennebula.org
6. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Exec Resource Type
6
7. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Exec Resource Type
● one-time commands
● does not deal well with changes
(yes, you can use refreshonly =>
true)
● was only capable of managing
all artefacts of a configuration
7
8. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Exec Resource Type
● root Shell with empty
environment
● “Emergency Exit” (Luke
Kanies - Berlin - Q4/2015)
8
9. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Exec Resource Type
9
11. Solution 2 - Defined Resource Type
File - Service Pattern
11
12. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Defined Resource Type
● (Package) - File - Service
pattern
● self defined resource type as
wrapper
● config artefact per title (data
from hash)
12
13. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Defined Resource Type
13
14. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Defined Resource Type
● Service Resource
● Always check hasrestart, hasstatus options
● Possibility to manage individual config artefacts
● Difficulty when changing parameters of an existing config
artefact -> restart = stop, start
● Wrapper shell script -> Exec replacement
14
16. Solution 3 - Custom Resource Type
Idempotent, non-breaking, prefetch capable configuration
16
17. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Custom Resource Type
17
18. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Custom Resource Type
18
20. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Types and Providers
● Are CLI tools / API’s available
?
● Can output be rendered in
structured data ?
20
22. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Type - Beginning
22
<module>/lib/puppet/type/my_file.rb
23. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Type - Properties and Parameters
● Properties
● everything you can set or modify (e.g. UID)
● Parameters
● change the way how the provider works (e.g. managehome)
23
24. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Type - Properties and Parameters
24
25. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Type - DSL
25
27. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Provider - Beginning
27
<module>/lib/puppet/provider/my_file/ruby.rb
28. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Provider - Running commands
28
29. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Provider - Properties and Parameters
● Getter
● read the existing state of an attribute
● Setter
● set the desired state of an attribute
● Idempotency
29
30. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Provider - Getters and Setters
30
31. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Provider - Create and Destroy
31
34. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Types and Providers
● exec in custom Providers
● running %x(...) or exec(...)
● use of restricted words
34
36. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Types and Providers
● one type
● one or more providers
● What do you want to manage?
● What may be changed ?
● What can be set on creation only ?
36
37. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Types and Providers
● Multiple providers will allow you
to react on
● New SW version with new CLI
format or new commands
● Different SW usage on
different OS
37
39. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Types and Providers
● Vendor forbids to edit config
files
● Vendor insists in using CLI tools
● e.g. IBM WebSphere
39
40. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Dear Enterprise Software producers
● give us code for our CfgMgmt
tool
● we want one tool to manage
everything
● we want to still have your
support for your software
40
43. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Ruby - Version and Tools
● Don’t mess your system Ruby
● RVM / rbenv
● Gems
● bundler
● wirble
● pry
43
44. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Ruby - ~/.irbrc
44
46. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Types & Providers - Examples
● Books
● https://www.amazon.com/Puppet-Types-Providers-Dan-Bode/
dp/1449339328
● Blogs
● http://garylarizza.com/blog/2013/11/25/fun-with-providers/
● https://www.enterprisemodules.com/blog/2014/01/puppet-
custom-types-the-easy-way/
● http://www.datacentred.co.uk/blog/puppet-custom-types/
46
47. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Types & Providers - Examples
● Docs
● https://docs.puppet.com/guides/custom_types.html
● https://docs.puppet.com/guides/provider_development.html
● https://docs.puppet.com/puppet/latest/reference/
lang_reserved.html
● Talks
● http://www.slideshare.net/TimCinel/writing-custom-puppet-
types-and-providers-to-manage-webbased-applications
47
49. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Moving from Exec to Types and Providers - Summary
● Exec is for one time commands only -
it is an emergency exit
● Types and Providers are not difficult
● Types have the Puppet DSL syntax,
Providers have Logic and Commands
49
50. Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016
Moving from Exec to Types and Providers - Summary
● Ruby is easy to learn
● Start with IRB + Wirble
● Use Pry Gem for debugging
● Start doing configuration the right way
● Use Puppet’s power for Extensions
50