solving real world data problems with jerakia

67
Solving real world data problems with Jerakia Craig Dunn, Config Management Camp, Ghent 2016

Upload: craig-dunn

Post on 15-Apr-2017

856 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Solving real world data problems with Jerakia

Solving real world data problems with JerakiaCraig Dunn, Config Management Camp, Ghent 2016

Page 2: Solving real world data problems with Jerakia

• Best practice

• Code base design

• Workflow mangement

• Scaling Puppet

• Installation and support

• Module writing

• Throughout Europe

www.enviatics.com

Page 3: Solving real world data problems with Jerakia

• Puppet user since 2008

• IT consultant for 15+ years

• Active community member

• The “Roles and Profiles” guy

• Problem solver

• Lives in Málaga, Spain.

• …. and hotels

• Daddy!

www.craigdunn.org

Craig Dunn

@crayfishx

Page 4: Solving real world data problems with Jerakia

A brief history of Puppet

Page 5: Solving real world data problems with Jerakia

In the beginning…

• Over complex code

• Unsharable modules

• Making simple changes required alot of skill.

The embedded data era

Page 6: Solving real world data problems with Jerakia

class ntp { if $env == ‘dev’ { $server = ‘dev.ntp.local’ } else { if $hostname == ‘gateway’ { $server = ‘pool.ntp.org’ } else { $server = ‘prod.ntp.local’ } } …}

Page 7: Solving real world data problems with Jerakia

And then…

Page 8: Solving real world data problems with Jerakia

HieraThe dawn of the data separation era

Page 9: Solving real world data problems with Jerakia

• Separation of data from code

• Module authors could write sharable re-usable code

• Code was less complex and more readable

• The Forge became useful

• Managing data became a lot easier

Page 10: Solving real world data problems with Jerakia

Hierarchical Search

Page 11: Solving real world data problems with Jerakia

Pluggable• Pluggable interchangable backends

• Data can be sourced from multiple formats

• hiera-eyaml

• hiera-mysql

• hiera-http

• hiera-redis

• hiera-consul

Page 12: Solving real world data problems with Jerakia
Page 13: Solving real world data problems with Jerakia

Managing our data is now a critical part of configuration management

Page 14: Solving real world data problems with Jerakia

Infrastructure grows and requirementsget more complex

Page 15: Solving real world data problems with Jerakia
Page 16: Solving real world data problems with Jerakia

• Different teams and customers require different hierarchies

• A particular application needs to source data from a different place

• Control access to sub-sets of data for teams within an organisation

• Dynamically generate the lookup hierarchy at runtime

• Group together application specific data into separate files

• Manage encrypted data from any data source

• Global hiera.yaml file creates restrictions

Page 17: Solving real world data problems with Jerakia

Introducing Jerakiajerakia.io

Page 18: Solving real world data problems with Jerakia

Jerakia• Data lookup tool

• Open source

• Extendable framework

• Solving the most complex edge cases

Page 19: Solving real world data problems with Jerakia

Jerakia• Can be used as a Hiera backend

• Can be wired directly into Puppet as a data binding terminus

• Drop in replacement for Hiera, or not.

Page 20: Solving real world data problems with Jerakia

Why Jerakia?

Page 21: Solving real world data problems with Jerakia

One design goal…

Page 22: Solving real world data problems with Jerakia

Flexibility

Page 23: Solving real world data problems with Jerakia

• Lookup behaviour written in Ruby DSL

• Almost everything is pluggable

• Inter-changable data sources

• Easy integration

• Hiera compatible*

Page 24: Solving real world data problems with Jerakia

$ gem install jerakia

Page 25: Solving real world data problems with Jerakia

$ puppet module install crayfishx/jerakia

Page 26: Solving real world data problems with Jerakia

• A request is received containing a key and a namespace

• A policy is chosen to perform the request

• One or more lookups are called to act on the request

• A response is sent back to the requestor

• Container for lookups

• Written in Ruby DSL

• Different policies for different apps

Policy File

Page 27: Solving real world data problems with Jerakia

An Example Jerakia Policy File

policy :main do lookup :default do datasource :file, { :docroot => "/var/jerakia/data", :format => :yaml, :searchpath => [ "host/#{scope[:hostname]}", "env/#{scope[:env]}", "common", ] } endend

Page 28: Solving real world data problems with Jerakia

An Example Jerakia Policy File

policy :main do lookup :default do datasource :file, { :docroot => "/var/jerakia/data", :format => :yaml, :searchpath => [ "host/#{scope[:hostname]}", "env/#{scope[:env]}", "common", ] } endend

Page 29: Solving real world data problems with Jerakia

An Example Jerakia Policy File

policy :main do lookup :default do datasource :file, { :docroot => "/var/jerakia/data", :format => :yaml, :searchpath => [ "host/#{scope[:hostname]}", "env/#{scope[:env]}", "common", ] } endend

Page 30: Solving real world data problems with Jerakia

An Example Jerakia Policy File

policy :main do lookup :default do datasource :file, { :docroot => "/var/jerakia/data", :format => :yaml, :searchpath => [ "host/#{scope[:hostname]}", "env/#{scope[:env]}", "common", ] } endend

Page 31: Solving real world data problems with Jerakia

• Lookups are contained within policies

• A policy can contain multiple lookups

• A lookup always contains at least a data source

Lookups

Page 32: Solving real world data problems with Jerakia

Scope

Handler

Request

Lookup

Plugins

Data Source

Output Filter

Response Data

Anatomy of a Jerakia lookup

Page 33: Solving real world data problems with Jerakia

Scope

Handler

Request

Lookup

Plugins

Data Source

Output Filter

Response Data

Anatomy of a Jerakia lookupRequest consists of a

lookup key, a namespace and some metadata

Page 34: Solving real world data problems with Jerakia

Scope

Handler

Request

Lookup

Plugins

Data Source

Output Filter

Response Data

Anatomy of a Jerakia lookupInformation to be

used in determining how data is looked up

Page 35: Solving real world data problems with Jerakia

Scope

Handler

Request

Lookup

Plugins

Data Source

Output Filter

Response Data

Anatomy of a Jerakia lookup

Lookup plugins can read and modify the scope and

request objects

Page 36: Solving real world data problems with Jerakia

Scope

Handler

Request

Lookup

Plugins

Data Source

Output Filter

Response Data

Anatomy of a Jerakia lookup

A pluggable data source is used to lookup data

Page 37: Solving real world data problems with Jerakia

Scope

Handler

Request

Lookup

Plugins

Data Source

Output Filter

Response Data

Anatomy of a Jerakia lookup

Data returned from the datasource is passed to a

pluggable output filter

Page 38: Solving real world data problems with Jerakia

Lookup methods

Page 39: Solving real world data problems with Jerakia

confine / exclude

Invalidates a lookup unless/if the criteria is met

confine request.namespsace[0], "apache"

confine request.namespsace[0], [ /website_.*/, "apache", "php" ]

Page 40: Solving real world data problems with Jerakia

Stop

Do not proceed to the next lookup if this lookup is valid

lookup :special do … confine request.namespsace[0], "apache" stopend

lookup :main do …

Page 41: Solving real world data problems with Jerakia

Datasources• Easily pluggable and extendable

• File and HTTP datasources shipped out-of-the-box

Page 42: Solving real world data problems with Jerakia

Datasources datasource :name, { :option => “value”… }

Page 43: Solving real world data problems with Jerakia

Datasource definitionlookup :main do

datasource :file, { :format => :yaml, :docroot => "/var/lib/jerakia", :searchpath => [ "host/#{scope[:certname]}", "env/#{scope[:environment]}", "common", ] }

end

/var/lib/jerakia/env/dev/apache.yaml

Page 44: Solving real world data problems with Jerakia

lookup :main do

datasource :file, { :format => :yaml, :docroot => "/var/lib/jerakia", :searchpath => [ "host/#{scope[:certname]}", "env/#{scope[:environment]}", "common", ] }

end

/var/lib/jerakia/env/dev/apache.yaml

Datasource definition

Page 45: Solving real world data problems with Jerakia

lookup :main do

datasource :file, { :format => :yaml, :docroot => "/var/lib/jerakia", :searchpath => [ "host/#{scope[:certname]}", "env/#{scope[:environment]}", "common", ] }

end

/var/lib/jerakia/env/dev/apache.yaml

Datasource definition

Page 46: Solving real world data problems with Jerakia

/var/lib/jerakia/env/dev/apache.yaml/var/lib/jerakia/env/dev/apache.d/www_corp_com.yaml/var/lib/jerakia/env/dev/apache.d/www_acme_net.yaml/var/lib/jerakia/env/dev/apache.d/www_fake_org.yaml

Fragments• Introduced in 0.4

• If a .d directory is found, files within are concatenated

• One document is returned

Page 47: Solving real world data problems with Jerakia

Data Layout :searchpath => [

"host/#{scope[:certname]}", "env/#{scope[:environment]}", ]

# cat /var/lib/jerakia/env/dev/apache.yaml—-port: 80

# cat /var/lib/jerakia/env/dev.yaml—-apache::port: 80

Hiera

Jerakia

Page 48: Solving real world data problems with Jerakia

Plugins• Access to request and scope

• Can read or modify on-the-fly

• Re-usable

• Cleaner code in policy files

Page 49: Solving real world data problems with Jerakia

class Jerakia::Lookup::Plugin module Mything def do_something … end endend

Writing plugins• Written as Ruby extensions

• Can be placed in the plugin dir

• Or shipped as rubygems

Page 50: Solving real world data problems with Jerakia

lookup :main, :use => :mything do plugin.mything.do_something …end

Using plugins• Plugins are loaded into the lookup

• Referenced as plugin.name.method

lookup :main, :use => [ :mything, :foo ] do …end

Page 51: Solving real world data problems with Jerakia

lookup :main, :use => :hiera do plugin.hiera.rewrite_lookup datasource :file, { :docroot => "/var/lib/jerakia", :format => :yaml, :searchpath => [ "env/#{scope[:environment]}", "common", ]end

The hiera plugin• Provides compatibility to hiera filesystem layouts

• Shipped with Jerakia

# cat /var/lib/jerakia/env/dev.yaml—-apache::port: 80

Page 52: Solving real world data problems with Jerakia

Output filters

• Pluggable

• Specified in the lookup

• Parses data returned from the datasource

Page 53: Solving real world data problems with Jerakia

Output filters

• Two are currently shipped

• Encryption (provided by eyaml*)

• Strsub

*https://github.com/TomPoulton/hiera-eyaml

Page 54: Solving real world data problems with Jerakia

Output filters

lookup :main do …

output_handler :encryptionend

Page 55: Solving real world data problems with Jerakia

Output filters

lookup :main do …

output_handler :encryptionend

Page 56: Solving real world data problems with Jerakia

Example User Story• Team in Ireland manage PHP/Apache

• Autonomous team that don’t manage infra

• Their optimal hierarchy is different from “ours”

• “We” need to service them from Puppet

• They must not modify infra services

• “We” also manage PHP/Apache for other clients

Page 57: Solving real world data problems with Jerakia

policy :default do lookup :main, do datasource :file, { :format => :yaml, :docroot => "/var/lib/jerakia", :searchpath => [ "hostname/#{scope[:fqdn]}", "environment/#{scope[:environment]}", "common" ], } end end

Our main lookup is responsible for the entire

infrastructure

Page 58: Solving real world data problems with Jerakia

policy :default do lookup :ireland do datasource :file, { :format => :yaml, :docroot => "/var/external/data/ie", :searchpath => [ "project/#{scope[:project]}", "common", ] } end lookup :main, do datasource :file, { :format => :yaml, :docroot => "/var/lib/jerakia", :searchpath => [ "hostname/#{scope[:fqdn]}", "environment/#{scope[:environment]}", "common" ], } end end

Lookup for the Ireland team added above the

main lookup with separate docroot and

searchpath

Page 59: Solving real world data problems with Jerakia

policy :default do lookup :ireland do datasource :file, { :format => :yaml, :docroot => "/var/external/data/ie", :searchpath => [ "project/#{scope[:project]}", "common", ] } confine scope[:location], "ie" confine request.namespace[0], [ "apache", "php", ] end lookup :main, do datasource :file, { :format => :yaml, :docroot => "/var/lib/jerakia", :searchpath => [ "hostname/#{scope[:fqdn]}", "environment/#{scope[:environment]}", "common" ], } end end

Only use this lookup if the requestor location is IE and the namespace is

apache or php

Page 60: Solving real world data problems with Jerakia

policy :default do lookup :ireland do datasource :file, { :format => :yaml, :docroot => "/var/external/data/ie", :searchpath => [ "project/#{scope[:project]}", "common", ] } confine scope[:location], "ie" confine request.namespace[0], [ "apache", "php", ] stop end lookup :main, do datasource :file, { :format => :yaml, :docroot => "/var/lib/jerakia", :searchpath => [ "hostname/#{scope[:fqdn]}", "environment/#{scope[:environment]}", "common" ], } end end

If this lookup is valid then do not proceed to the

main lookup, even if data is not found.

Page 61: Solving real world data problems with Jerakia

Command line $ jerakia lookup port —namespace apache

$ jerakia help lookupUsage: jerakia lookup [KEY]

Options: c, [--config=CONFIG] # Configuration file p, [--policy=POLICY] # Lookup policy # Default: default n, [--namespace=NAMESPACE] # Lookup namespace t, [--type=TYPE] # Lookup type # Default: first s, [--scope=SCOPE] # Scope handler # Default: metadata [--scope-options=key:value] # Key/value pairs to be passed to the scope handler m, [--merge-type=MERGE_TYPE] # Merge type # Default: array l, [--log-level=LOG_LEVEL] # Log level v, [--verbose], [--no-verbose] # Print verbose information D, [--debug], [--no-debug] # Debug information to console, implies --log-level debug d, [--metadata=key:value] # Key/value pairs to be used as metadata for the lookup

Lookup [KEY] with Jerakia

Page 62: Solving real world data problems with Jerakia

Integration with Puppet—-:backends: - jerakia

[master] . . . data_binding_terminus = jerakia

Page 63: Solving real world data problems with Jerakia

Roadmap & Contributing

Page 64: Solving real world data problems with Jerakia

Upcoming in 0.5• Data Schemas

• Better REST client/server

• Deep merge behaviour

• Lookup plugin “load method”

Page 65: Solving real world data problems with Jerakia

Contributions wanted• Code maturity

• Caching

• Features

• Bugfixes

• Documentation

• #jerakia (freenode) Sponsored by

Page 66: Solving real world data problems with Jerakia

Jerakia 1.0

Page 67: Solving real world data problems with Jerakia

Thank youQuestions?

jerakia.io

@crayfishx