A basic introduction
Francisco MartÃnez
Puppet Camp Barcelona 2013
Usually, in the different environments of a project, you have copies of you machines with very similar behavior
BUT
different data, as machines will refer to each other
In the example, the backend in development will have a connection string refering to db-dev
mongodb://db-dev:2500/?replicaSet=test
while the other backends point to their respective db servers
mongodb://db-prod:2500/?replicaSet=real
How to configure the backend is code.
The reference to the db server is data.
(To be more specific, environment-specific data)
Worthwhile read IMHO:
https://puppetlabs.com/blog/the-problem-with-separating-data-from-puppet-code/
Proposes different solutions to the problem
$dnsserver = hiera('dnsserver')
:hierarchy:
- location
- global
location
" and if I don't find my key, go search for it in "global
"
hiera.yaml
):---
:backends:
- yaml
:hierarchy:
- %{::clientcert}
- %{::environment}
- virtual_%{::is_virtual}
- common
:yaml:
:datadir: /etc/puppet/hieradata
:hierarchy:
we put data sourcescommon
)development.yaml
db_connect_string: 'mongodb://db-dev:2500/?replicaSet=devel'
backend_base_url: 'http://backend-devel.example.com/apirest'
puppet_interval: '5'
production.yaml
db_connect_string: 'mongodb://db-prod:3500/?replicaSet=prod'
backend_base_url: 'http://backend-prod.example.com/apirest'
puppet_interval: '720'
nameserver.example.com.yaml
puppet_interval: '120'
virtual_true.yaml
puppet_interval: '60'
common.yaml
puppet_interval: '15'
if
or case
clauses :)class web_server ($port = 80) {...
class web_server ( ) {
hiera('web_server::port')
}
openstack::all:
admin_email: devnull@example.com
keystone_admin_token: G6943LMReKj_kqdAVrAiPbpRloAfE1fqp0eVAJ
rabbitmq:
user: rabbitmq
password: secret
$data = hiera_hash('openstack::all')
$rabbitmq_user = $data['rabbitmq']['user']
hiera()
: performs a simple lookup, stops searching after it finds a valuehiera_array()
: returns a flattened array with all the matching valueshiera_hash()
: returns one merged hash with all the values returnedhiera_include()
: looks up as in hiera_array()
and then includes each classname returned web01.example.com.yaml
---
classes:
- apache
- redis
- wordpress
common.yaml
---
classes:
- base::linux
site.pp
hiera_include(classes)
include
function will rely on external data for parameters<class name::parameter name>
apache::version
hiera_include()
function to set up an ENC-like behavior with hierasite.pp
node default {
hiera_include("classes")
}
datacenter-mad.yaml
---
classes:
- ntp
ntp::server: ntp-mad.example.com
datacenter-bcn.yaml
---
classes:
- ntp
ntp::server: ntp-bcn.example.com
node "devel-*" {
--- # Favorite movies, Array/List
- Matrix
- Sucker Punch
- Scott Pilgrim vs. the World
- American Psycho
--- # domains and countries, Hash/Dictionary
de: 'Germany'
sk: 'Slovakia'
hu: 'Hungary'
us: 'United States'
no: 'Norway'