SlideShare a Scribd company logo
Copyright example42 GmbH - 2016
Puppet 4 - Data in Modules
PuppetCamp Paris 2016
Martin Alfke - ma@example42.com
Image: Tatlin - tatlin.net
Copyright example42 GmbH - 2016
Copyright example42 GmbH - 2016
Martin Alfke
!
Berlin/Germany
!
CEO example42 GmbH
Freelance Puppet Expert
Network
!
Puppet since 2007
!
Puppet Trainer, Consultant
!
Co-Author of “Puppet 4
Essentials”
Copyright example42 GmbH - 2016
Puppet 4
Data in Modules
• Separation of Code and Data
• Data in Modules
• Lookup Priority
• Data in Component Modules
• Data in Environments
Copyright example42 GmbH - 2016
Separation of
Code and Data
Image: Tatlin - tatlin.net
Copyright example42 GmbH - 2016
Separation of
Code and Data
• data in code
class my_ntp {!
!if $::environment == ‘dev’ {!
$ntp_server = [‘pool.ntp.org’]!
} else {!
if $::facts[‘fqdn’] == ‘ntp1.example42.com’
{!
# switch back to ntp1 when issue is solved!
$ntp_server = [‘ntp2.example42.com’]!
} else {!
$ntp_server = [‘127.0.0.1’]!
}!
}!
Copyright example42 GmbH - 2016
Separation of
Code and Data
• explicit lookup
• hiera(‘key’[, ‘default’][, ‘override hierarchy’])
Copyright example42 GmbH - 2016
Separation of
Code and Data
• implicit lookup
class my_ntp (!
!Array $ntp_server,!
) {!
!# …!
}!
!
contain my_ntp!
!
# hiera data!
my_ntp::ntp_server:!
- ‘pool.ntp.org’!
Copyright example42 GmbH - 2016
Separation of
Code and Data
• hiera.yaml
# version 1!
:backends:!
- yaml!
:yaml:!
:datadir: “/etc/puppetlabs/code/
environments/%{environment}/hieradata”!
:hierarchy:!
- “nodes/%{::trusted.certname}”!
- “os/%{::facts[‘os’][‘osfamily’]}”!
- common!
Copyright example42 GmbH - 2016
Separation of
Code and Data
• hieradata
os/Debian.yaml
apache::pkgname:!
- ‘apache2’!
- ‘apache2-ssl’!
!
os/RedHat.yaml
apache::pkgname:!
- ‘httpd’!
!
common.yaml
apache::purge_configs: true!
Copyright example42 GmbH - 2016
Separation of
Code and Data
• hieradata
os/FreeBSD.yaml
apache::pkgname:!
- ‘apache’!
Copyright example42 GmbH - 2016
Separation of
Code and Data
• puppet code
# apache/manifests/params.pp
class apache::params {!
case $::operatingsystem {!
‘Debian’: { # … }!
‘RedHat’: { # … }!
default: {!
fail(‘OS not supported’)!
}!
}!
}!
Copyright example42 GmbH - 2016
Data in Modules
Image: Tatlin - tatlin.net
Copyright example42 GmbH - 2016
Lookup Priority
Image: Tatlin - tatlin.net
Copyright example42 GmbH - 2016
Lookup Priority
• Hiera -> Global Overrides
!
!
!
Copyright example42 GmbH - 2016
Lookup Priority
• Hiera -> Global Overrides
!
• Environment Data -> Core Puppet Lookup
!
Copyright example42 GmbH - 2016
Lookup Priority
• Hiera -> Global Overrides
!
• Environment Data -> Core Puppet Lookup
!
• Module Data -> Defaults
Copyright example42 GmbH - 2016
Lookup Functions
• Explicit lookup: lookup(‘key’)!
!
• CLI lookup: puppet lookup ‘key’
!
• Automatic lookup: ‘<namespace>::<key>’
Copyright example42 GmbH - 2016
Lookup Functions
• lookup(‘key’, <Type>, <merge_behavior>, <default>)!
• e.g. lookup(‘ntp_servers’, Array)
• Merge behavior:
• first!
• unique (array merge)!
• hash!
• deep!
Copyright example42 GmbH - 2016
Data Provider
Configuration
• Global Environment Provider: puppet.conf
• environment_data_provider = <data provider>!
!
!
!
Copyright example42 GmbH - 2016
Data Provider
Configuration
• Global Environment Provider: puppet.conf
• environment_data_provider = <data provider>!
• Environment Provider: environment.conf
• environment_data_provider = <data provider>!
!
Copyright example42 GmbH - 2016
Data Provider
Configuration
• Global Environment Provider: puppet.conf
• environment_data_provider = <data provider>!
• Environment Provider: environment.conf
• environment_data_provider = <data provider>!
• Module Provider: metadata.json
• “data_provider”: “<data provider>”
Copyright example42 GmbH - 2016
Data Provider
• none -> standard hiera lookup
!
• hiera -> hiera lookup (hiera v4)
!
• function -> data function lookup
Copyright example42 GmbH - 2016
Data Provider
Hiera
• replace hiera, hiera_array, hiera_hash with ‘lookup’
• needs hiera.yaml v4 configuration file
• set data_provider to ‘hiera’ in puppet.conf,
environment.conf or metadata.json
• modify global hiera.yaml to use datadir outside
environment
Copyright example42 GmbH - 2016
Data Provider
Hiera
# /etc/puppetlabs/code/environments/production/hiera.yaml
# /etc/puppetlabs/code/environments/production/modules/<module>/
hiera.yaml
#
- - -!
version: 4!
datadir: hieradata!
hierarchy:!
- name: “Nodes”!
backend: yaml!
path: “nodes/%{trusted.certname}”!
- name: “OS”!
backend: json!
path: “os/%{facts.os.family}”!
- name: “common”!
backend: yaml
Copyright example42 GmbH - 2016
Data Provider
Function
• write data function
• Puppet 4 Function
• <module>/functions/<module>/data.pp
• <env>/functions/<env>/data.pp
• set data_provider to function in puppet.conf,
environment.conf or metadata.json
Copyright example42 GmbH - 2016
Data Provider
Function - Puppet
# ntp/functions/ntp/data.pp
function ntp::data() {!
$params = {!
‘ntp::ntpservers’ => [‘pool.ntp.org’],!
}!
$os_params = case $facts[‘os’][‘family’] {!
‘Debian’: {!
{ ‘ntp::ntpackage’ => ‘ntpd’, }!
},!
default: {!
{}!
}!
}!
$params + $os_params!
}
Copyright example42 GmbH - 2016
Data Provider
Function
• write data function
• Ruby Function (Puppet 4 function API)
• <module>/lib/puppet/functions/<module>/
data.rb
• <env>/lib/puppet/functions/<env>/data.rb
• set data_provider to function in puppet.conf,
environment.conf or metadata.json
Copyright example42 GmbH - 2016
Data Provider
Function - Ruby
# ntp/lib/puppet/functions/ntp/data.rb
Puppet::Functions.create_function(:’ntp::data’) do!
def base_data()!
{ ‘ntp::ntpservers’ => [‘pool.ntp.org’], }!
end!
def os_data()!
case Facter.value(:os)[‘family’]!
when ‘Debian’!
{ ‘ntp::pkgname’ => ‘ntpd’, }!
else!
{}!
end!
def data()!
self.base_data.merge!(self.os_data)!
end!
end
Copyright example42 GmbH - 2016
Data in Component Modules
Image: Tatlin - tatlin.net
Copyright example42 GmbH - 2016
Data in Component Modules
• add data provider to metadata.json
• provide OS defaults
• remove params.pp / remove inheritance
• allow users to overwrite any data
Copyright example42 GmbH - 2016
Data Provider
Function - Ruby
# my_ntp/manifests/init.pp
class my_ntp (!
$server = $my_ntp::params::server,!
$pkgname = $my_ntp::params::pkgname,!
$secure = $my_ntp::params::secure,!
) inherits my_ntp::params {!
# ...!
}!
Copyright example42 GmbH - 2016
Data in Environments
Image: Tatlin - tatlin.net
Copyright example42 GmbH - 2016
Data in Environments
• old hiera replacement
• add hiera.yaml to environment base path
• overwrite data from modules, roles & profiles
Copyright example42 GmbH - 2016
Summary
Image: Tatlin - tatlin.net
Copyright example42 GmbH - 2016
Summary
# /etc/puppetlabs/code/
! ! hiera.yaml!
! ! hieradata/!
! ! environments/production/
! ! ! ! ! ! environment.conf!
! ! ! ! ! ! hiera.yaml!
! ! ! ! ! ! hieradata/!
modules/my_module/
! ! ! ! ! ! ! ! ! ! metadata.json!
! ! ! ! ! ! ! ! ! ! hiera.yaml!
! ! ! ! ! ! ! ! ! ! hieradata/
Copyright example42 GmbH - 2016
Summary
# /etc/puppetlabs/code/
! ! hiera.yaml!
! ! hieradata/!
! ! environments/production/
! ! ! ! ! environment.conf!
! ! ! ! ! lib/functions/data.pp!
! ! ! ! ! lib/puppet/functions/ !
! ! ! ! ! ! ! ! production/data.rb!
modules/my_module/
! ! ! ! ! ! !! ! metadata.json!
! ! ! ! ! ! ! ! lib/functions/data.pp!
! ! ! ! ! ! ! ! lib/puppet/functions/ !
! ! ! ! ! ! ! ! ! ! ! my_module/data.rb
Copyright example42 GmbH - 2016
Summary - Pro
• Per hierarchy Hiera Data backend possible
• Data Function lookups without need for hiera
backend (e.g. Cloud Management API data)
• No more inheritance required
Copyright example42 GmbH - 2016
Summary - Con
• No single Source of Authority?
• Debugging can be complex when iterating over
many data providers and hierarchies
Copyright example42 GmbH - 2016
Module Developers
• switch to data in modules
• give users the possibility to provide own data
• allow users to overwrite any data
• allow users to know their data for missing OS
support
Copyright example42 GmbH - 2016
Module Users
• switch to hieradata in modules
then
• switch to data in environments
• keep data simple and readable
• don’t overcomplicate !
Copyright example42 GmbH - 2016
Module Users
• hieradata
common.yaml
my_ntp: ‘pool.ntp.org’!
apache::default_mods: false!
apache::purge_configs: true!
mysql::remove_default_accounts: true!
mysql::root_password: ‘puppet’!
oradb::database::version: ’12.1’!
oradb::shout: ‘MISSING DATA’
Copyright example42 GmbH - 2016
References
• http://docs.puppetlabs.com/puppet/4.3/reference/
lookup_quick.html
• http://docs.puppetlabs.com/puppet/4.3/reference/
lookup_quick_module.html
• http://puppet-on-the-edge.blogspot.de/2015/01/
puppet-40-data-in-modules-and.html
Copyright example42 GmbH - 2016
Puppet 4 - Data in modules
PuppetCamp Paris 2016
Martin Alfke - ma@example42.com
Image: Tatlin - tatlin.net
Copyright example42 GmbH - 2016

More Related Content

PDF
Modules of the twenties
PDF
Puppet Systems Infrastructure Construction Kit
PDF
Developing IT infrastructures with Puppet
PDF
Puppet camp2021 testing modules and controlrepo
PDF
Puppet: From 0 to 100 in 30 minutes
PPTX
Enjoying the Journey from Puppet 3.x to Puppet 4.x (PuppetConf 2016)
PPTX
Puppetizing Your Organization
PDF
Can you upgrade to Puppet 4.x?
Modules of the twenties
Puppet Systems Infrastructure Construction Kit
Developing IT infrastructures with Puppet
Puppet camp2021 testing modules and controlrepo
Puppet: From 0 to 100 in 30 minutes
Enjoying the Journey from Puppet 3.x to Puppet 4.x (PuppetConf 2016)
Puppetizing Your Organization
Can you upgrade to Puppet 4.x?

What's hot (20)

PDF
Puppet modules: An Holistic Approach
PDF
Puppet for Sys Admins
PDF
Creating a mature puppet system
PDF
Puppet Continuous Integration with PE and GitLab
PPTX
Auto Deploy Deep Dive – vBrownBag Style
PPTX
How to build your own OpenStack distro using Puppet OpenStack
PDF
Essential applications management with Tiny Puppet
PDF
Puppet Camp Dallas 2014: How Puppet Ops Rolls
PDF
Our Puppet Story (Linuxtag 2014)
PDF
Tp install anything
PDF
Puppet @ Seat
PDF
Puppet control-repo 
to the next level
PDF
Puppet evolutions
PDF
Writing Custom Puppet Types and Providers to Manage Web-Based Applications
PDF
Puppet modules: A Holistic Approach - Geneva
PPTX
Troubleshooting Puppet
PDF
Testing for Ops: Going Beyond the Manifest - PuppetConf 2013
PDF
Bootstrapping Puppet and Application Deployment - PuppetConf 2013
KEY
Puppet for dummies - ZendCon 2011 Edition
PDF
Unit Testing Lots of Perl
Puppet modules: An Holistic Approach
Puppet for Sys Admins
Creating a mature puppet system
Puppet Continuous Integration with PE and GitLab
Auto Deploy Deep Dive – vBrownBag Style
How to build your own OpenStack distro using Puppet OpenStack
Essential applications management with Tiny Puppet
Puppet Camp Dallas 2014: How Puppet Ops Rolls
Our Puppet Story (Linuxtag 2014)
Tp install anything
Puppet @ Seat
Puppet control-repo 
to the next level
Puppet evolutions
Writing Custom Puppet Types and Providers to Manage Web-Based Applications
Puppet modules: A Holistic Approach - Geneva
Troubleshooting Puppet
Testing for Ops: Going Beyond the Manifest - PuppetConf 2013
Bootstrapping Puppet and Application Deployment - PuppetConf 2013
Puppet for dummies - ZendCon 2011 Edition
Unit Testing Lots of Perl
Ad

Similar to Puppet Camp Paris 2016 Data in Modules (20)

PDF
Puppet getting started by Dirk Götz
PDF
Writing and Sharing Great Modules with the Puppet Forge
PDF
Writing & Sharing Great Modules on the Puppet Forge - Puppet Camp Raleigh
PDF
Love / Hate Puppet (Puppet Gotchas)
PDF
Modules reduce reuse_recycle
PDF
Our Puppet Story (GUUG FFG 2015)
PDF
Can puppet help you run docker on a T2.Micro?
PPTX
Automation using Puppet 3
PDF
Going beyond Code: Driving automation with data via Hiera
PDF
Going beyond Code: Driving automation with data via Hiera
PDF
Puppet and your Metadata - PuppetCamp London 2015
PDF
Puppet Camp Berlin 2015: Martin Alfke | The Power of Puppet 4
PDF
Puppet Camp Berlin 2015: The Power of Puppet 4
PDF
Puppet Modules for Fun and Profit
PDF
Puppet modules for Fun and Profit
PPTX
Short lived immutable servers with masterless puppet
PDF
CfgMgmtCamp 2023 - Puppet is YAML.pdf
PPTX
Puppet & Perforce: Versioning Everything for Deployments
PDF
Puppet Keynote by Ralph Luchs
PDF
Puppet Camp Berlin 2015: Nigel Kersten | Puppet Keynote
Puppet getting started by Dirk Götz
Writing and Sharing Great Modules with the Puppet Forge
Writing & Sharing Great Modules on the Puppet Forge - Puppet Camp Raleigh
Love / Hate Puppet (Puppet Gotchas)
Modules reduce reuse_recycle
Our Puppet Story (GUUG FFG 2015)
Can puppet help you run docker on a T2.Micro?
Automation using Puppet 3
Going beyond Code: Driving automation with data via Hiera
Going beyond Code: Driving automation with data via Hiera
Puppet and your Metadata - PuppetCamp London 2015
Puppet Camp Berlin 2015: Martin Alfke | The Power of Puppet 4
Puppet Camp Berlin 2015: The Power of Puppet 4
Puppet Modules for Fun and Profit
Puppet modules for Fun and Profit
Short lived immutable servers with masterless puppet
CfgMgmtCamp 2023 - Puppet is YAML.pdf
Puppet & Perforce: Versioning Everything for Deployments
Puppet Keynote by Ralph Luchs
Puppet Camp Berlin 2015: Nigel Kersten | Puppet Keynote
Ad

More from Martin Alfke (16)

PDF
HashiTalksDACH-Terraform-Managing training instances in the Cloud
PDF
PuppetCamp2021-Testing Modules and ControlRepo.pdf
PDF
Puppet Camp Germany 2020 - Puppet Control Repo and GIT
PDF
DevOps - How to get technical buy in
PDF
ADDO 2019 DevOps in a containerized world
PDF
OpenRheinRuhr 2018 - Ops hates containers! Why?
PDF
PuppetConf 2016 Moving from Exec to Types and Provides
PDF
Power of Puppet 4
PDF
Upgrading Puppet CommitterConf Essen 2014
PDF
GUUG Hamburg OpenNebula
PDF
Puppet camp london-modulerewritingsmartway
PDF
PDF
Puppet future parser
PDF
developing sysadmin, sysadmining developersGuug devops puppet
PDF
Gluster fs buero20_presentation
PDF
Puppet buero20 presentation
HashiTalksDACH-Terraform-Managing training instances in the Cloud
PuppetCamp2021-Testing Modules and ControlRepo.pdf
Puppet Camp Germany 2020 - Puppet Control Repo and GIT
DevOps - How to get technical buy in
ADDO 2019 DevOps in a containerized world
OpenRheinRuhr 2018 - Ops hates containers! Why?
PuppetConf 2016 Moving from Exec to Types and Provides
Power of Puppet 4
Upgrading Puppet CommitterConf Essen 2014
GUUG Hamburg OpenNebula
Puppet camp london-modulerewritingsmartway
Puppet future parser
developing sysadmin, sysadmining developersGuug devops puppet
Gluster fs buero20_presentation
Puppet buero20 presentation

Recently uploaded (20)

PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PDF
Triggering QUIC, presented by Geoff Huston at IETF 123
PPTX
international classification of diseases ICD-10 review PPT.pptx
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
DOCX
Unit-3 cyber security network security of internet system
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PPTX
Digital Literacy And Online Safety on internet
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PPTX
Introduction to Information and Communication Technology
PDF
The Internet -By the Numbers, Sri Lanka Edition
PDF
Testing WebRTC applications at scale.pdf
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PPTX
Funds Management Learning Material for Beg
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
Unit-1 introduction to cyber security discuss about how to secure a system
SASE Traffic Flow - ZTNA Connector-1.pdf
Triggering QUIC, presented by Geoff Huston at IETF 123
international classification of diseases ICD-10 review PPT.pptx
Decoding a Decade: 10 Years of Applied CTI Discipline
Unit-3 cyber security network security of internet system
522797556-Unit-2-Temperature-measurement-1-1.pptx
The New Creative Director: How AI Tools for Social Media Content Creation Are...
Tenda Login Guide: Access Your Router in 5 Easy Steps
Digital Literacy And Online Safety on internet
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
Job_Card_System_Styled_lorem_ipsum_.pptx
Introduction to Information and Communication Technology
The Internet -By the Numbers, Sri Lanka Edition
Testing WebRTC applications at scale.pdf
Introuction about WHO-FIC in ICD-10.pptx
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
Funds Management Learning Material for Beg
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION

Puppet Camp Paris 2016 Data in Modules

  • 1. Copyright example42 GmbH - 2016 Puppet 4 - Data in Modules PuppetCamp Paris 2016 Martin Alfke - ma@example42.com Image: Tatlin - tatlin.net Copyright example42 GmbH - 2016
  • 2. Copyright example42 GmbH - 2016 Martin Alfke ! Berlin/Germany ! CEO example42 GmbH Freelance Puppet Expert Network ! Puppet since 2007 ! Puppet Trainer, Consultant ! Co-Author of “Puppet 4 Essentials”
  • 3. Copyright example42 GmbH - 2016 Puppet 4 Data in Modules • Separation of Code and Data • Data in Modules • Lookup Priority • Data in Component Modules • Data in Environments
  • 4. Copyright example42 GmbH - 2016 Separation of Code and Data Image: Tatlin - tatlin.net
  • 5. Copyright example42 GmbH - 2016 Separation of Code and Data • data in code class my_ntp {! !if $::environment == ‘dev’ {! $ntp_server = [‘pool.ntp.org’]! } else {! if $::facts[‘fqdn’] == ‘ntp1.example42.com’ {! # switch back to ntp1 when issue is solved! $ntp_server = [‘ntp2.example42.com’]! } else {! $ntp_server = [‘127.0.0.1’]! }! }!
  • 6. Copyright example42 GmbH - 2016 Separation of Code and Data • explicit lookup • hiera(‘key’[, ‘default’][, ‘override hierarchy’])
  • 7. Copyright example42 GmbH - 2016 Separation of Code and Data • implicit lookup class my_ntp (! !Array $ntp_server,! ) {! !# …! }! ! contain my_ntp! ! # hiera data! my_ntp::ntp_server:! - ‘pool.ntp.org’!
  • 8. Copyright example42 GmbH - 2016 Separation of Code and Data • hiera.yaml # version 1! :backends:! - yaml! :yaml:! :datadir: “/etc/puppetlabs/code/ environments/%{environment}/hieradata”! :hierarchy:! - “nodes/%{::trusted.certname}”! - “os/%{::facts[‘os’][‘osfamily’]}”! - common!
  • 9. Copyright example42 GmbH - 2016 Separation of Code and Data • hieradata os/Debian.yaml apache::pkgname:! - ‘apache2’! - ‘apache2-ssl’! ! os/RedHat.yaml apache::pkgname:! - ‘httpd’! ! common.yaml apache::purge_configs: true!
  • 10. Copyright example42 GmbH - 2016 Separation of Code and Data • hieradata os/FreeBSD.yaml apache::pkgname:! - ‘apache’!
  • 11. Copyright example42 GmbH - 2016 Separation of Code and Data • puppet code # apache/manifests/params.pp class apache::params {! case $::operatingsystem {! ‘Debian’: { # … }! ‘RedHat’: { # … }! default: {! fail(‘OS not supported’)! }! }! }!
  • 12. Copyright example42 GmbH - 2016 Data in Modules Image: Tatlin - tatlin.net
  • 13. Copyright example42 GmbH - 2016 Lookup Priority Image: Tatlin - tatlin.net
  • 14. Copyright example42 GmbH - 2016 Lookup Priority • Hiera -> Global Overrides ! ! !
  • 15. Copyright example42 GmbH - 2016 Lookup Priority • Hiera -> Global Overrides ! • Environment Data -> Core Puppet Lookup !
  • 16. Copyright example42 GmbH - 2016 Lookup Priority • Hiera -> Global Overrides ! • Environment Data -> Core Puppet Lookup ! • Module Data -> Defaults
  • 17. Copyright example42 GmbH - 2016 Lookup Functions • Explicit lookup: lookup(‘key’)! ! • CLI lookup: puppet lookup ‘key’ ! • Automatic lookup: ‘<namespace>::<key>’
  • 18. Copyright example42 GmbH - 2016 Lookup Functions • lookup(‘key’, <Type>, <merge_behavior>, <default>)! • e.g. lookup(‘ntp_servers’, Array) • Merge behavior: • first! • unique (array merge)! • hash! • deep!
  • 19. Copyright example42 GmbH - 2016 Data Provider Configuration • Global Environment Provider: puppet.conf • environment_data_provider = <data provider>! ! ! !
  • 20. Copyright example42 GmbH - 2016 Data Provider Configuration • Global Environment Provider: puppet.conf • environment_data_provider = <data provider>! • Environment Provider: environment.conf • environment_data_provider = <data provider>! !
  • 21. Copyright example42 GmbH - 2016 Data Provider Configuration • Global Environment Provider: puppet.conf • environment_data_provider = <data provider>! • Environment Provider: environment.conf • environment_data_provider = <data provider>! • Module Provider: metadata.json • “data_provider”: “<data provider>”
  • 22. Copyright example42 GmbH - 2016 Data Provider • none -> standard hiera lookup ! • hiera -> hiera lookup (hiera v4) ! • function -> data function lookup
  • 23. Copyright example42 GmbH - 2016 Data Provider Hiera • replace hiera, hiera_array, hiera_hash with ‘lookup’ • needs hiera.yaml v4 configuration file • set data_provider to ‘hiera’ in puppet.conf, environment.conf or metadata.json • modify global hiera.yaml to use datadir outside environment
  • 24. Copyright example42 GmbH - 2016 Data Provider Hiera # /etc/puppetlabs/code/environments/production/hiera.yaml # /etc/puppetlabs/code/environments/production/modules/<module>/ hiera.yaml # - - -! version: 4! datadir: hieradata! hierarchy:! - name: “Nodes”! backend: yaml! path: “nodes/%{trusted.certname}”! - name: “OS”! backend: json! path: “os/%{facts.os.family}”! - name: “common”! backend: yaml
  • 25. Copyright example42 GmbH - 2016 Data Provider Function • write data function • Puppet 4 Function • <module>/functions/<module>/data.pp • <env>/functions/<env>/data.pp • set data_provider to function in puppet.conf, environment.conf or metadata.json
  • 26. Copyright example42 GmbH - 2016 Data Provider Function - Puppet # ntp/functions/ntp/data.pp function ntp::data() {! $params = {! ‘ntp::ntpservers’ => [‘pool.ntp.org’],! }! $os_params = case $facts[‘os’][‘family’] {! ‘Debian’: {! { ‘ntp::ntpackage’ => ‘ntpd’, }! },! default: {! {}! }! }! $params + $os_params! }
  • 27. Copyright example42 GmbH - 2016 Data Provider Function • write data function • Ruby Function (Puppet 4 function API) • <module>/lib/puppet/functions/<module>/ data.rb • <env>/lib/puppet/functions/<env>/data.rb • set data_provider to function in puppet.conf, environment.conf or metadata.json
  • 28. Copyright example42 GmbH - 2016 Data Provider Function - Ruby # ntp/lib/puppet/functions/ntp/data.rb Puppet::Functions.create_function(:’ntp::data’) do! def base_data()! { ‘ntp::ntpservers’ => [‘pool.ntp.org’], }! end! def os_data()! case Facter.value(:os)[‘family’]! when ‘Debian’! { ‘ntp::pkgname’ => ‘ntpd’, }! else! {}! end! def data()! self.base_data.merge!(self.os_data)! end! end
  • 29. Copyright example42 GmbH - 2016 Data in Component Modules Image: Tatlin - tatlin.net
  • 30. Copyright example42 GmbH - 2016 Data in Component Modules • add data provider to metadata.json • provide OS defaults • remove params.pp / remove inheritance • allow users to overwrite any data
  • 31. Copyright example42 GmbH - 2016 Data Provider Function - Ruby # my_ntp/manifests/init.pp class my_ntp (! $server = $my_ntp::params::server,! $pkgname = $my_ntp::params::pkgname,! $secure = $my_ntp::params::secure,! ) inherits my_ntp::params {! # ...! }!
  • 32. Copyright example42 GmbH - 2016 Data in Environments Image: Tatlin - tatlin.net
  • 33. Copyright example42 GmbH - 2016 Data in Environments • old hiera replacement • add hiera.yaml to environment base path • overwrite data from modules, roles & profiles
  • 34. Copyright example42 GmbH - 2016 Summary Image: Tatlin - tatlin.net
  • 35. Copyright example42 GmbH - 2016 Summary # /etc/puppetlabs/code/ ! ! hiera.yaml! ! ! hieradata/! ! ! environments/production/ ! ! ! ! ! ! environment.conf! ! ! ! ! ! ! hiera.yaml! ! ! ! ! ! ! hieradata/! modules/my_module/ ! ! ! ! ! ! ! ! ! ! metadata.json! ! ! ! ! ! ! ! ! ! ! hiera.yaml! ! ! ! ! ! ! ! ! ! ! hieradata/
  • 36. Copyright example42 GmbH - 2016 Summary # /etc/puppetlabs/code/ ! ! hiera.yaml! ! ! hieradata/! ! ! environments/production/ ! ! ! ! ! environment.conf! ! ! ! ! ! lib/functions/data.pp! ! ! ! ! ! lib/puppet/functions/ ! ! ! ! ! ! ! ! ! production/data.rb! modules/my_module/ ! ! ! ! ! ! !! ! metadata.json! ! ! ! ! ! ! ! ! lib/functions/data.pp! ! ! ! ! ! ! ! ! lib/puppet/functions/ ! ! ! ! ! ! ! ! ! ! ! ! my_module/data.rb
  • 37. Copyright example42 GmbH - 2016 Summary - Pro • Per hierarchy Hiera Data backend possible • Data Function lookups without need for hiera backend (e.g. Cloud Management API data) • No more inheritance required
  • 38. Copyright example42 GmbH - 2016 Summary - Con • No single Source of Authority? • Debugging can be complex when iterating over many data providers and hierarchies
  • 39. Copyright example42 GmbH - 2016 Module Developers • switch to data in modules • give users the possibility to provide own data • allow users to overwrite any data • allow users to know their data for missing OS support
  • 40. Copyright example42 GmbH - 2016 Module Users • switch to hieradata in modules then • switch to data in environments • keep data simple and readable • don’t overcomplicate !
  • 41. Copyright example42 GmbH - 2016 Module Users • hieradata common.yaml my_ntp: ‘pool.ntp.org’! apache::default_mods: false! apache::purge_configs: true! mysql::remove_default_accounts: true! mysql::root_password: ‘puppet’! oradb::database::version: ’12.1’! oradb::shout: ‘MISSING DATA’
  • 42. Copyright example42 GmbH - 2016 References • http://docs.puppetlabs.com/puppet/4.3/reference/ lookup_quick.html • http://docs.puppetlabs.com/puppet/4.3/reference/ lookup_quick_module.html • http://puppet-on-the-edge.blogspot.de/2015/01/ puppet-40-data-in-modules-and.html
  • 43. Copyright example42 GmbH - 2016 Puppet 4 - Data in modules PuppetCamp Paris 2016 Martin Alfke - ma@example42.com Image: Tatlin - tatlin.net Copyright example42 GmbH - 2016