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

Post on 14-Feb-2017

83 views 3 download

Transcript of 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.

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

example42 GmbH - Berlin / Germany

Martin Alfke CEO & Co-Founder

2

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

3

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

Solution 1 - Exec Resource TypeRun the CLI tools

5

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

Exec Resource Type

6

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

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

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

Exec Resource Type

9

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

10

Solution 2 - Defined Resource TypeFile - Service Pattern

11

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

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

Defined Resource Type

13

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

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

15

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

16

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

Custom Resource Type

17

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

Custom Resource Type

18

Types and ProvidersBasic concept

19

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

TypesDescribe Puppet DSL Syntax

21

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

Type - Beginning

22

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

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

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

Type - Properties and Parameters

24

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

Type - DSL

25

ProvidersCommand Logic

26

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

Provider - Beginning

27

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

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

Provider - Running commands

28

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

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

Provider - Getters and Setters

30

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

Provider - Create and Destroy

31

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

32

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

33

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

DoWhat you want to do.

35

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

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

Why Types and ProvidersManage an Enterprise Application

38

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

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

Types and ProvidersPart #5 - How to start

41

RubyVersion and Tools

42

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

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

Ruby - ~/.irbrc

44

Types & ProvidersImplementation Examples

45

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

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

Types and ProvidersPart #6 - Summary

48

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

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