“It is not the strongest of the species that survive, nor the most intelligent, but the one most responsive to change.” — Charles Darwin

“DevOps is a set of practices that seeks to reduce the gap between software development and software operation.”

Puppet Roles and Parameter Hierarchies like Chef

This is a design pattern to implement roles like Chef and to separate class parameters into a parameter hierarchy also like chef. Chef has two very useful features:

1. Roles
  A server node can have a role like say webserver. Then the cookbooks and recipes ( modules and classes in Puppet terminology) that make up a webserver are related to the role rather that the server node.

2. Attribute Precedence.
  Attributes (class Parameters in Puppet terminology) are kept separate from the cookbook (class) code and are applied in a hierarchy of cookbook,recipe,node,role etc.

This has several advantages:
1. Servers are defined by their roles not their hostnames.
2. Data is separated from code.
3. Easier to write and use generic library modules and classes from the puppet forge.
4. Easier to view and change the parameters of a role
5. Ability to have different parameters for different environments (test, Prod etc).

I have build a design pattern called puppet_roles_hiera_parameters to implement these in puppet.

Puppet 3.3 incorporate hiera, a hierarchical keyword value store which is very useful to implement a separation of class parameter values from the class module code.

The roles can be either set on the individual server or on the puppetmaster in the hieradata.
If set in the puppetmaster hieradata this takes precedence.

a. TO SET THE ROLES ON EACH INDIVIDUAL SERVER - MASTERLESS PUPPET:

    export FACTER_role_name1=base
    export FACTER_role_name2=webserver
    puppet apply --modulepath ./modules manifests/site.pp

b. TO SET THE ROLES ON THE PUPPETMASTER IN THE HIERADATA:

  on the puppetmaster set the roles in the nodes/.yaml file using values
    role::role_name1 to role::role_name4
  for example for a server with a host name of pb65test create a file hieradata/nodes/pb65test.yaml
    ----
    role::role_name1: 'base'
    role::role_name2: 'webserver'


For more details see the role module on Puppet Forge

References
Github - puppet_roles_hiera_parameters
roles and profiles
Role-based Puppet with Hiera
Github - vagrant-roles-demo
Github - puppet-roles
About Roles
Puppet for chef users

0 comments:

Post a Comment