Sei sulla pagina 1di 12

Hiera

the new extlookup

What is hiera?

Just another way to store and lookup data in


puppet

How is it different?
Extlookup stores data in CSV format

Hiera stores data in YAML format

Why Hiera?

Its fast.

Extlookup can only return one unit of data at a


time. Parses CSV file for each data required.

Hiera can lookup a bunch of data and store it in


memory. Only one-time parsing required for each
bunch of data.

Show me some code

exlookup(key, default_value, filename)

hiera(key, default_value, filename)

They're same!

Data sample

CSV:
extlookup('host/directi.com/address');
extlookup('host/directi.com/hostgroups')
host/directi.com/address/115.114.213.35
host/directi.com/hostgroups/common

YAML:
hiera('hosts') # => { 'directi.com' => { 'address' => '115.114.213.25',
'hostgroups' => 'common' } }
hosts:
directi.com:
address: 115.114.213.25
hostgroups: common

CSV does two calls to lookup for reading the two values, hence parses the
file twice.
Hiera reads the value in one call (and stores as ruby hash), hence parses
the file only once.

Things relevant to puppet

Data files location-

manifests/production/extdata and
manifests/production/sysad_servers/monitor
ing/extdata have been merged into
manifests/production/hieradata

*.csv have been renamed to *.yaml

How do I add a new nagios host?!

Comparision with old CSV way:


host/newhost.com/param1,value1
host/newhost.com/param2,value2
host/newhost2.com/param3,value3
host/newhost2.com/param4,value4

YAML way:
hosts:
newhost.com:

param1: value1
param2: value2
newhost2.com:
param3: value3
param4: value4

I want to move all data from


manifests to YAMLs

The sequence of data files that are looked up


for data: (similar to precendence of filelookup)
- "project_colo_hostname"
- "project_hostname"
- "project_colo_class_hostname"
- "project_class_hostname"
- "project_colo_class"
- "project_class"
- "project_colo"
- "project_class_subclass_colo"
- "project_class_subclass"
- "project"
- common

Moving data to YAMLs: example


/-------- ntp_dc1.yaml ----------\

/ -------- ntp_dc2.yaml --------\

| ntpserver: ntp1.dc1.example.com |

| ntpserver: ntp1.dc2.example.com |

| sysadmin: dc1noc@example.com

\-------------------------------/

\-------------------------------/

/
\

/------------- ntp.yaml -------------\


| ntpserver: 1.pool.ntp.org

| sysadmin: sysadmin@%{domain}

|
\----------------------------------/

Lookup calls

hiera('ntpserver') returns data from most


relevant data file.
hiera_array('ntpserver') returns array of values
found in data files in the precedence list.
For DC1: ($project = ntp; $class = dc1)

hiera('ntpserver') => 'ntp.dc1.example.com'

hiera_array('ntpserver') => ['1.pool.ntp.org',


'ntp.dc1.example.com']

Questions?

Potrebbero piacerti anche