{"id":3023,"date":"2013-12-09T20:38:34","date_gmt":"2013-12-09T19:38:34","guid":{"rendered":"http:\/\/www.devco.net\/?p=3023"},"modified":"2013-12-09T23:22:08","modified_gmt":"2013-12-09T22:22:08","slug":"the-problem-with-params-pp","status":"publish","type":"post","link":"https:\/\/www.devco.net\/archives\/2013\/12\/09\/the-problem-with-params-pp.php","title":{"rendered":"The problem with params.pp"},"content":{"rendered":"

My recent post about using Hiera data in modules has had a great level of discussion already, several thousand blog views, comments, tweets and private messages on IRC. Thanks for the support and encouragement – it’s clear this is a very important topic.<\/p>\n

I want to expand on yesterdays post by giving some background information on the underlying motivations that caused me to write this feature and why having it as a forge module is highly undesirable but the only current option.<\/p>\n

At the heart of this discussion is the params.pp<\/em> pattern and general problems with it. To recap, the basic idea is to embed all your default data into a file params.pp typically in huge case statements and then reference this data as default. Some examples of this are the puppetlabs-ntp module<\/a>, the Beginners Guide to Modules<\/a> and the example I had in the previous post that I’ll reproduce below:<\/p>\n

<\/p>\n

\r\n# ntp\/manifests\/init.pp\r\nclass ntp (\r\n     # allow for overrides using resource syntax or data bindings\r\n     $config = $ntp::params::config,\r\n     $keys_file = $ntp::params::keys_file\r\n   ) inherits ntp::params {\r\n\r\n   # validate values supplied\r\n   validate_absolute_path($config)\r\n   validate_absolute_path($keys_file)\r\n\r\n   # optionally derive new data from supplied data\r\n\r\n   # use data\r\n   file{$config:\r\n      ....\r\n   }\r\n}\r\n<\/pre>\n

<\/code><\/p>\n

<\/p>\n

\r\n# ntp\/manifests\/params.pp\r\nclass ntp::params {\r\n   # set OS specific values\r\n   case $::osfamily {\r\n      'AIX': {\r\n         $config = \"\/etc\/ntp.conf\"\r\n         $keys_file = '\/etc\/ntp.keys'\r\n      }\r\n\r\n      'Debian': {\r\n         $config = \"\/etc\/ntp.conf\"\r\n         $keys_file = '\/etc\/ntp\/keys'\r\n      }\r\n\r\n      'RedHat': {\r\n         $config = \"\/etc\/ntp.conf\"\r\n         $keys_file = '\/etc\/ntp\/keys'\r\n      }\r\n\r\n      default: {\r\n         fail(\"The ${module_name} module is not supported on an ${::osfamily} based system.\")\r\n      }\r\n   }\r\n}\r\n<\/pre>\n

<\/code><\/p>\n

Now today as Puppet stands this is pretty much the best we can hope for. This achieves a lot of useful things:<\/p>\n