ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

20
Austin Puppet Users Group (ATXPUG) Managing Puppet Complexity

Transcript of ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

Page 1: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

Austin Puppet Users Group

(ATXPUG)

Managing Puppet Complexity

Page 2: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

Modules & Complexity

Complexity is generally used to characterize something with many parts where those parts interact with each other in multiple ways.

Page 3: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

Style

• Make quality a requirement

• Know when to stop (don’t over optimize)

• DRY – Don’t Repeat Yourself

Page 4: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

DRY – Don’t repeat yourself

• Imposed Duplication – Apparent lack of choice

• Inadvertent Duplication – Not realize that they’re duplicating information

• Impatient Duplication – lazy / duplicate because it seems easier

• Interdeveloper Duplication – Multiple people on teams / multiple teams.

Page 5: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

Code

• Keep low level knowledge in code

• Reserve Comments for high level expectations

• Foster an environment where it’s easier to find and reuse existing stuff than to write it yourself.

Page 6: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

Avoid Global data

• Every time you reference global data it ties you to the other components that share data – frowned upon since 2.x days but still in a lot of puppet code

Page 7: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

Orthogonal - Safe to Fail

• Independent / lightly coupled systems

– Eliminates effects of unrelated things

– Design self contained things

• Increased productivity & contained risk

Page 8: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

Prototype (experiment)

• Architecture

• New functionality in existing systems

• Structure or contents of external data

• Third party tools or components

• Performance issues

• User interface / experience / design

Page 9: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

Experiements

• Worry less about correctness, completeness, robustness and style.

• Focus on design / definition

• Is coupling minimized?

• Can you identify potential sources of duplication?

Page 10: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

Style Guides

• https://docs.puppetlabs.com/guides/style_guide.html

Page 11: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

Test

• Loosely coupled systems easier to test –interactions between components are limited.

– Unit testing is easier

– Test in CI pipeline

• Beaker / rspect / puppet lint

Page 12: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

Refactor

• Avoid code rot. Don’t let bad code fester and turn all your code into abandonware

Page 13: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

It’s code

• Version control

• Test

• Refactor

• Share.

• forge

Page 14: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

Module Template

• Puppet Module Generate – use the boiler plate

• Use Garethr’s boiler plate – nice & updated

https://github.com/garethr/puppet-module-skeleton (more assumptions though)

Page 15: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

Data Separation

• Some use hiera.. Me no like

• ENC

– Puppet PE

– Foreman

– Homebrew

– ?

• Single source of truth? How?

Page 16: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

Parameterized Classes

• Great for ENCs

• Easy to set default values

• Portable / Shareable

Page 17: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

Class Inheritance

• Use within a module to reduce repetition (DRY)

• Inheriting from other modules decreases modularity, but hard to avoid

– ENC confusion

Page 18: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

Code Defensively

• Catch unexpected events before they break things – gracefully bow out if you don’t support platform

• Puppet Future parser helps –

– Line error failure reporting

– Type checking (out of stdlib)

Page 19: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

I wish

• More modules exposed puppet resources

• Augeus (or similar) was internalized across every platform so there was an easy meta catalog instead of is osfamily = yaddy yaddyyadda

• Open source puppet had strong direction.. 3.7 PE is out.. What next for OS?

Page 20: ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code

Discussions

• I’m out of slides, time for interaction