Re: [Puppet Users] Negate or uninclude a class

Bruce Richardson
Mon, 18 Oct 2010 09:38:48 -0000

On Mon, Oct 18, 2010 at 02:19:38AM -0700, luke.bigum
wrote:
> Hi guys,
>
> Is there any functionality to negate or uninclude a class so as to
> stop it''s resources being declared? I''m thinking along
the lines of
> having some classes included by default, but in very select
> circumstances to not include it. For example, LDAP auth on all servers
> except the actual LDAP servers themselves.

No, you can''t uninclude a class.

>
> Is the only way to do this to inherit the base class and override all
> it''s resources to do the equivalent of "ensure =>
absent", then
> something like "if (tagged(class)) { include undo-subclass } "
where
> needed?

You''ll have to do it the other way round and optionally include.  In
the
base server class, have a little block like

if $ldap_auth {
	include ldap::auth
}

Then just make sure that this variable is set true by default and set it
explicitly to false for your ldap servers, either in their nodes or
(more logically) in the ldap server class.

You *could* do it with overrides but only If you were using a define
within your base class for part of the setup and that define took a
parameter which told it whether to include the ldap class.  Trivial
example:

-----------------------------------------------------------------

define includer ( $include = true ) {
        if $include {
                include ldap
        }
}

class base {
        includer { ''setup'': }
}

class child inherits base {
        Includer[''setup''] { include => false }
}

-----------------------------------------------------------------

I wouldn''t do it that way unless there were other specific benefits to
the define, though.  The variable method is simpler.

--
Bruce

What would Edward Woodward do?