{"id":3351,"date":"2016-03-06T11:35:30","date_gmt":"2016-03-06T10:35:30","guid":{"rendered":"https:\/\/www.devco.net\/?p=3351"},"modified":"2016-03-16T11:25:48","modified_gmt":"2016-03-16T10:25:48","slug":"params-pp-in-puppet-4","status":"publish","type":"post","link":"https:\/\/www.devco.net\/archives\/2016\/03\/06\/params-pp-in-puppet-4.php","title":{"rendered":"params.pp in Puppet 4"},"content":{"rendered":"
I do not like the params.pp pattern<\/a>. Puppet 4 has brought native Data in Modules<\/a> that’s pretty awesome and to a large extend it removes the traditional need for params.pp<\/em>.<\/p>\n Thing is, we kind of do still need some parts of params.pp. To understand this we have to consider what the areas of concern params.pp has in Puppet world:<\/p>\n Points 1 and 3 are roughly sorted out by Puppet 4 types and data in modules, but what about the 2nd point and to some extend more complex data validation that falls outside of the type system?<\/p>\n Before I start looking at how to derive data though I’ll take a look at the new function API in Puppet 4.<\/p>\n \nPuppet has a DSL for managing systems, we think it’s awesome and can do everything you need. But in order to use it you have to learn 2 programming languages with different models.\n<\/p><\/blockquote>\n And I always felt the same about the general suggestion to write ENCs etc, luckily not something we hear much these days.<\/p>\n And they had a few major issues:<\/p>\n The Puppet 4 functions API fix this, you can write functions in the native DSL and they work fine in environments. The Puppet 4 DSL with it’s loops and blocks and so forth have matured enough that it can do a lot of the things I’d need to do for deriving data from other data.<\/p>\n They live in your module in the functions<\/em> directory, they’re namespaced and environment safe:<\/p>\n And you’d use this like any other function: $x = mymod::myfunc(10)<\/em>. Simple stuff, whatever is the last value is returned like in Ruby.<\/p>\n Update:<\/strong> these have now been documented in the Puppet Labs docs<\/a>\n
Native Functions<\/H3>
\nPuppet has always allowed us to write functions but they needed to be in Ruby and nothing else. This isn’t really great. The message is kind of: <\/p>\n\n
\r\nfunction mymod::myfunc(Fixnum $input) {\r\n $input * 2\r\n}\r\n<\/pre>\n
\nDerived Data in Puppet 4<\/H3>
\nSo we’re finally where I can show my preferred method for deriving data in Puppet 4, and that’s to use a native function.<\/p>\n