Writing modules to gracefully skip OS's they don't support

83 views
Skip to first unread message

Danny Roberts

unread,
Oct 7, 2014, 10:14:42 AM10/7/14
to puppet...@googlegroups.com
Is it possible to make a module simply not be applied at all if it encounters an OS it does not support?

Currently doing a check for the OS and outputting a "fail" is standard amongst modules but this ends the Puppet run for the client if it has a module assigned that does this.

The use case is such that assigning a module that fails unless it finds a certain OS version to all nodes in Hiera like we do in my workplace via 'common.yaml' would cause all servers that do not match a required OS to fail it's Puppet runs from then on.

The only way I can think is to wrap most/all of the module's resources in if statements making the same OS checks again & again, which seems wasteful. Does anyone have an idea on how to do this better or is it something we should just ignore?

Felix Frank

unread,
Oct 7, 2014, 11:21:40 AM10/7/14
to puppet...@googlegroups.com
Hi,

making modules into noop is a fairly dangerous design, because your
manifest can and will just silently fail.

If you really *need* to assign dysfunctional features to your nodes, let
your profiles module take care of sorting them out based on facts.

profile::cool_linux_only_app {
if $kernel == "Linux" {
# include stuff
}
}

That is assuming you are using roles/profiles. If you are not, then you
have an excuse to start now ;-)

Regards,
Felix

jmp242

unread,
Oct 10, 2014, 10:28:58 AM10/10/14
to puppet...@googlegroups.com

I may be doing something really stupid per Felix.Frank, but we decided to make all our modules have:

Case $kernel {

    'linux': {

}

   'windows'{

}

}

form... It seems to work well for us?

Atom Powers

unread,
Oct 10, 2014, 12:29:09 PM10/10/14
to puppet...@googlegroups.com
While this sounds like a good idea, I would argue that it breaks the principle of leas surprise.

If I assign a module to a server I would expect that module to do what it is intended to do. If it can't do that and it doesn't tell me that it can't do that then I may assume that the module has done it's work and the server is OK when that isn't actually the case.

You can declare your modules only where they are functional. Instead of putting them in common.yaml configure hiera to look for ${kernel}.yaml or  ${lsbrelease}.yaml and declare your module only in the places where it works.

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/4c143008-659a-416e-aaa1-6fd3a43e931c%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Perfection is just a word I use occasionally with mustard.
--Atom Powers--

Felix Frank

unread,
Oct 10, 2014, 7:13:14 PM10/10/14
to puppet...@googlegroups.com
On 10/10/2014 04:28 PM, jmp242 wrote:
> I may be doing something really stupid per Felix.Frank, but we decided
> to make all our modules have:

Come, now. I said it was "dangerous". As often, this is a result of
actually being a bit too clever.

I'm trying hard not to be Linus (anymore ;-)
Reply all
Reply to author
Forward
0 new messages