Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

70
Delegated Cong with Multiple Hiera Databases Robert Terhaar [email protected] Atlantic Dynamic NYC PuppetConf 2014 - September 24

description

Delegated Configuration with Multiple Hiera Databases - Robert Terhaar, Atlantic Dynamic

Transcript of Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Page 1: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Delegated Config with Multiple

Hiera DatabasesRobert Terhaar [email protected] Atlantic Dynamic NYC

PuppetConf 2014 - September 24

Page 2: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Company & Personal Bio

• Build custom cloud, automation, deployment, and management systems for:

• Finance // Bio-Tech // Start-ups // Advertising

• Sysadmin since 1998

• Puppet user since 2007

• Based in NYC 🗽

Page 3: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Hiera Databaseswith Multiple

Delegated Config

Page 4: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

What is Hiera?

Page 5: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Hiera is a framework for hierarchically

organizing data, and abstracting it from

your puppet manifests.

Page 6: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

With Hiera, you can externalize your data, and easily understand

how configuration data is assigned to your servers.

Page 7: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

What data belongs in Hiera?

Page 8: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Keep your secrets in

Hiera

Page 9: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

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

Secrets in Hiera

Page 10: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Store your business-

logic in Hiera

Page 11: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Store all OS-specific config in params.pp

Page 12: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Hiera is not params.pp

Page 13: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Business Logic (Hiera) vs.

OS-Specific Config (params.pp)• Servers in production: use database IP 10.0.0.1

• In us-east1: use NTP server 167.88.119.29

• On RHEL7: SELINUX=enforcing

• Package names for Apache on Debian/RHEL: apache2/httpd

• 1 CPU = default to 1 workerbut on 4 CPUs = default to 5 workers

Page 14: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

A Basic Hiera Example

Page 15: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Hiera Basics

$servers = hiera('ntp::servers')

As a Puppet Function

Page 16: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Hiera BasicsFunction in a parameterized class

class ntp( $servers = hiera('ntp::servers'),) { < ntp config goes here… >}

Page 17: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Hiera BasicsImplicit Lookup w/ Data Bindingsclass ntp( $servers,) { < ntp config goes here… >}

Page 18: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Hiera Basics

$servers = hiera(‘ntp::servers’, )

As a Puppet Function, w/ Default

‘pool.ntp.org’

Page 19: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

$ cat /etc/puppet/hiera.yaml ---:backends: - yaml!:logger: console!:hierarchy: - "fqdn/%{fqdn}" - "role/%{role}" - "lifecycle/%{lifecycle}" - "location/%{location}" - common!:yaml: :datadir: /etc/puppet/hieradb

Page 20: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

$ tree /etc/puppet/hieradb!

"## lifecycle$   "## dev.yaml$   "## production.yaml$   &## staging.yaml"## location$   &## us-east1.yaml&## os "## rhel6.yaml &## rhel7.yaml

Page 21: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Hiera supports multiple storage

backends

Page 22: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

• eyaml • http (REST) • mysql • postgres

• redis • mongodb • json • yaml • and more…

Page 23: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

$ cat /etc/puppet/hiera.yaml ---:backends:!!!:logger: console!:hierarchy: - "fqdn/%{fqdn}" - "role/%{role}" - "lifecycle/%{lifecycle}" - "location/%{location}" - common!:yaml: :datadir: /etc/puppet/hieradb!:postgres: :datadir: /etc/puppet/hieradb :host: <hostname> :user: <username> :pass: <password> :database: <database>

- yaml- postgres

Page 24: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

$ tree /etc/puppet/hieradb!

"## lifecycle$   "## dev.yaml$   "##$   "## production.yaml$   &## staging.yaml"## location$   &## us-east1.yaml&## os "## rhel6.yaml &## rhel7.yaml

production.sql

Page 25: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

But, let’s not focus on the tools… yet

Page 26: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Designing the solution

Page 27: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

“Good design is as little design as possible”

https://www.vitsoe.com/us/about/good-design

Page 28: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Design and Architecture

http://commons.wikimedia.org/wiki/File:Fallingwater_%28Kaufmann_Residence_by_Frank_Lloyd_Wright%29_-_26_June_2012.jpg

Page 29: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

“Architecture is the stuff that's hard to change later.

And there should be as little of that stuff as possible.”

- Martin Fowler

http://martinfowler.com/ieeeSoftware/whoNeedsArchitect.pdf

Page 30: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Semantics !

Architecture: Concrete Bricks !

Design: LEGO® Blocks

Page 31: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

The Setup

Page 32: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Everyone ElseDevOps Team

Node

resource

resource

resource

resource

Node

resource

resource

resource

resource

environments

modules

hierapuppetdb

manifeststemplates

! - fqdn/%{::fqdn}! - lifecycle/%{::lifecycle}! - location/%{::location}! - os/%{::osfamily}! - common

Puppet Master

Page 33: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Everyone ElseDevOps Team

hiera

! - fqdn/%{::fqdn}! - lifecycle/%{::lifecycle}! - location/%{::location}! - os/windows.yml! - common

Page 34: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Everyone Else!! ntp::servers = [! “server1.corp”,! “server2.corp”,! ]

DevOps Team

hiera

! - fqdn/%{::fqdn}! - lifecycle/%{::lifecycle}! - location/%{::location}! - os/windows.yml! - common

Page 35: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Delegation

Page 36: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Step 1

Page 37: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Develop the Problem

Statement.

Page 38: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

We need a way to delegate access to a few Hiera keys.

Page 39: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

We need a way to delegate access to a few Hiera keys.

Page 40: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Colleagues who are not in the “DevOps Team” need to manage

a few pre-defined parameters. (but only on a subset of servers)

Page 41: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Everyone Else!! ntp::servers = [! “server1.corp”,! “server2.corp”,! ]

Special People Club

hiera

! - fqdn/%{::fqdn}! - lifecycle/%{::lifecycle}! - location/%{::location}! - os/windows.yml! - common

Colleagues who are not in the “DevOps Team” need to manage a

few pre-defined parameters. (but only on a subset of servers)

Page 42: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Step 2

Page 43: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Gathering Requirements

Page 44: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Requirement: The Solution Must Fly

Page 45: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Don’t over-engineer

Page 46: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Don’t over-engineer your

solution

Page 47: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Don’t over-engineer your requirements

document

Page 48: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Requirement “Types”

http://en.wikipedia.org/wiki/Requirements_analysis#Types_of_Requirements

Page 49: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

• What are we building (1-2 sentence overview)

• What are the basic goals? (write them down!)

• How will we know when it’s done?

• What assumptions are we are making?

• What are some risks?

The Requirements Document

Page 50: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

• Get feedback from…

• your boss

• the client

• your colleagues

• other stakeholders

The Requirements Document

Page 51: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Iterate the doc

Page 52: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Own the doc

Page 53: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Be Realistic & Prioritize

Page 54: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Feedback, Surprises

Page 55: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

The Results

Page 56: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

What are we building? !

We are building a data import system for Hiera which allows secure delegated access to end users. The system filters data, and can import data from various external systems.

Page 57: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

• Import filtered data from various sources to a database. !

• That database is secondary Hiera backend datastore. !

• Adding additional import sources should be simple. !

• Easy to understand where keys are imported from.

Goals

Page 58: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

How will we know when it’s done? The first version will be complete once we: • Build a prototype • Document the solution • Test importing data from a few sources • Create a deployment plan • Deploy to production

Page 59: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Step 3

Page 60: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Brainstorm, and Prototype

Page 61: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

The solution without design

Page 62: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Everyone Else!!

UPDATE windows!SET value=‘[“server1.corp”, “server2.corp”]!WHERE key=‘ntp::servers’;

DevOps Team

hiera

We need a way to delegate access to a few Hiera keys.

PostgreSQL &! hiera-postgresql-

backend

! - fqdn/%{::fqdn}! - lifecycle/%{::lifecycle}! - location/%{::location}! - os/windows.sql! - common

windows.sql! ———! ntp::servers: SELECT value FROM windows WHERE key=‘ntp::servers’;

Single SQL Hiera Backend

Page 63: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

The designed solution

Page 64: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Importer !App

Puppet!Master

Node

Node

resource

resource

resource

resource

resource

resource

resource

resource

DevOps Team

Delegated Hiera DB

Primary Hiera DB

filter

Everyone Else

Import Plugin 1

Import Plugin 2External

Data Source 2

White List!(What keys & namespaces are allowed)

Authoritative Hiera Data

External Data

Source 1

Simple data import script (run via cron)

The slightly better solution (logical diagram)

Page 65: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Custom Hiera Backend

The slightly better solution (with implementation detail)

Importer !App

Puppet!Master

Node

Node

resource

resource

resource

resource

resource

resource

resource

resource

DevOps Team

Delegated Hiera DB

Primary Hiera DB

filter

Everyone Else

Import Plugin 1

Import Plugin 2External

Data Source 2

External Data

Source 1

Python import script, with pluggable import backends

PostgreSQL DB

CMDB API, and LDAP

.yaml files stored in git

Page 66: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Results

Page 67: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Intentional design, and stakeholder

feedback will lead to a better solution.

Page 68: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

DevOps Team

Everyone Else

Page 69: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Useful Resources

Good Design: https://www.vitsoe.com/us/about/good-design Learn More about Hiera: http://garylarizza.com/blog/2013/12/08/when-to-hiera/ Postgres Hiera Backend: https://github.com/adrianlzt/hiera-postgres-backend Hiera Encryption (eyaml): https://github.com/TomPoulton/hiera-eyaml Requirements: http://en.wikipedia.org/wiki/Requirements_analysis

Page 70: Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014

Robert Terhaar [email protected] Atlantic Dynamic - NYC

PuppetConf 2014 - September 24

Questions?

Thank You!