+ All Categories
Home > Technology > PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Date post: 14-Feb-2017
Category:
Upload: puppet
View: 83 times
Download: 3 times
Share this document with a friend
51
Moving from Exec to Types and Providers This is not a talk, more a story.
Transcript
Page 1: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Moving from Exec to Types and ProvidersThis is not a talk, more a story.

Page 2: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016

example42 GmbH - Berlin / Germany

Martin Alfke CEO & Co-Founder

2

Page 3: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

The Story begins ...Part #1 - Puppet Module using Exec CLI

3

Page 4: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

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

Page 5: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Solution 1 - Exec Resource TypeRun the CLI tools

5

Page 6: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016

Exec Resource Type

6

Page 7: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

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

Page 8: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

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

Page 9: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016

Exec Resource Type

9

Page 10: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

The Story continues ...Part #2 - Puppet Module using Defined Resource Types

10

Page 11: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Solution 2 - Defined Resource TypeFile - Service Pattern

11

Page 12: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

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

Page 13: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016

Defined Resource Type

13

Page 14: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

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

Page 15: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

The Story continues ...Part #3 - Puppet Module using Custom Resource Types

15

Page 16: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Solution 3 - Custom Resource TypeIdempotent, non-breaking, prefetch capable configuration

16

Page 17: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016

Custom Resource Type

17

Page 18: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016

Custom Resource Type

18

Page 19: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Types and ProvidersBasic concept

19

Page 20: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

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

Page 21: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

TypesDescribe Puppet DSL Syntax

21

Page 22: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016

Type - Beginning

22

<module>/lib/puppet/type/my_file.rb

Page 23: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

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

Page 24: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016

Type - Properties and Parameters

24

Page 25: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016

Type - DSL

25

Page 26: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

ProvidersCommand Logic

26

Page 27: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016

Provider - Beginning

27

<module>/lib/puppet/provider/my_file/ruby.rb

Page 28: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016

Provider - Running commands

28

Page 29: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

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

Page 30: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016

Provider - Getters and Setters

30

Page 31: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016

Provider - Create and Destroy

31

Page 32: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Types and ProvidersPart #4 - Do’s and don’t’s

32

Page 33: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Dont’sWhat you don’t want to do - please.

33

Page 34: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

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

Page 35: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

DoWhat you want to do.

35

Page 36: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

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

Page 37: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

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

Page 38: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Why Types and ProvidersManage an Enterprise Application

38

Page 39: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

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

Page 40: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

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

Page 41: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Types and ProvidersPart #5 - How to start

41

Page 42: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

RubyVersion and Tools

42

Page 43: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

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

Page 44: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Moving from Exec to Types and providers - Martin Alfke © example42 GmbH 2016

Ruby - ~/.irbrc

44

Page 45: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Types & ProvidersImplementation Examples

45

Page 46: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

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

Page 47: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

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

Page 48: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Types and ProvidersPart #6 - Summary

48

Page 49: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

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

Page 50: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

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

Page 51: PuppetConf 2016: Moving from Exec to Types and Providers – Martin Alfke, example42 GmbH

Recommended