Mapping $system to puppet

24 views
Skip to first unread message

Igor Galić

unread,
Jul 3, 2014, 8:11:34 PM7/3/14
to puppe...@googlegroups.com

Hi folks,

last week I proposed we add a function to puppetlabs-apache which
converts puppet booleans to httpd's On/Off.

https://github.com/puppetlabs/puppetlabs-apache/pull/782

of course that has no straight-forward approach, because in some
cases httpd will allow boolean values, as well as strings

https://httpd.apache.org/docs/current/mod/core.html#acceptpathinfo
https://httpd.apache.org/docs/current/mod/core.html#usecanonicalname

to name only a few.
My first throw of naming the function bool2httpd(), allowing it to map

/on/i, /true/i, true, 1, => 'On'
/off/i, /false/i, false, 0, nil, :undef => 'Off'

and otherwise, simply returning whatever we got lead to the effect of
having a *bad* name. Looking at it now, the solution to this seems
simple: Rename the function to normalise_bool(), allow it an optional
parameter (a regex?) that validates the outliers.


But what about the general problem of mapping a sub-system's directives
and the values they can take to puppet-friendly names, and validating
their types and ranges? It seems a lot of energy is expended in our
manifests, templates, or types/providers to that task.
Especially when a system has a rich set of directives, this can become
very cumbersome.

If you have similar pains, I invite you to share your stories here.
Maybe someone can think of a solution for your problem, or maybe
we can even find a more general solution.


So long,
-- i
Igor Galić

Tel: +43 (0) 664 886 22 883
Mail: i.g...@brainsware.org
URL: http://brainsware.org/
GPG: 8716 7A9F 989B ABD5 100F 4008 F266 55D6 2998 1641

Henrik Lindberg

unread,
Jul 3, 2014, 9:13:30 PM7/3/14
to puppe...@googlegroups.com
On 2014-04-07 2:11, Igor Galić wrote:
>
> Hi folks,
>
> last week I proposed we add a function to puppetlabs-apache which
> converts puppet booleans to httpd's On/Off.
>
> https://github.com/puppetlabs/puppetlabs-apache/pull/782
>
> of course that has no straight-forward approach, because in some
> cases httpd will allow boolean values, as well as strings
>
> https://httpd.apache.org/docs/current/mod/core.html#acceptpathinfo
> https://httpd.apache.org/docs/current/mod/core.html#usecanonicalname
>
> to name only a few.
> My first throw of naming the function bool2httpd(), allowing it to map
>
> /on/i, /true/i, true, 1, => 'On'
> /off/i, /false/i, false, 0, nil, :undef => 'Off'
>
> and otherwise, simply returning whatever we got lead to the effect of
> having a *bad* name. Looking at it now, the solution to this seems
> simple: Rename the function to normalise_bool(), allow it an optional
> parameter (a regex?) that validates the outliers.
>
>
> But what about the general problem of mapping a sub-system's directives
> and the values they can take to puppet-friendly names, and validating
> their types and ranges? It seems a lot of energy is expended in our
> manifests, templates, or types/providers to that task.
> Especially when a system has a rich set of directives, this can become
> very cumbersome.
>
This what the new Puppet Type System in Puppet 4.0 is intended to help
with. As an example, if you want a type that captures boolean
true/false, integers 0 and 1, and a set of enumerators you can write
that as:

assert_type( Variant[Boolean, Enum[on, off, yes, no], Integer[0,1]], $x)

There is an Enum like type that accepts regular expressions as well
instead of literal strings.

The types can also be used as optionally typed parameters in classes,
defines, and lambdas.

Checkout my blog posts about the type system for more information.

--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

Reply all
Reply to author
Forward
0 new messages