On Jan 7, 2007, at 7:29 PM, Nathan Dabney wrote:
> I need to know how to do the following in puppet.
>
> Say I have three classes, (c1,c2,c3) that are not related. These
> classes could be considered "attributes" that may or may not
apply
> to an individual host on my network. I need to know how to write a
> manifest, or series of manifests to allow me trigger a command
> (call it ''foo'') if all three classes are defined. I also
need to
> be able to trigger a different command (bar) if c1 and c3 are
> defined, but c2 is not.
>
> How would this look in puppet?
>
> For those of you familiar with cfengine, this would be similar to:
>
> c1.c2.c3::
> foo
>
> c1.!c2.c3::
> bar
Puppet has some support for thinking of classes as cfengine does, but
I don''t think many use it so it''s not all that developed.
Basically, classes in cfengine are equivalent to tags in Puppet. If
you include a class in Puppet, then the host gets tagged with that
class:
class yayness {
exec { "/bin/echo yayness": }
}
include yayness
if tagged(yayness) {
exec { "/bin/echo in yayness": }
}
Produces:
notice: /Exec[/bin/echo in yayness]/returns: executed successfully
notice: /yayness/Exec[/bin/echo yayness]/returns: executed successfully
The only quirk right now is that tagging is (unfortunately) file-
order dependent. That is, you can only test for tags after the
classes have been included. I hope to find a way to fix this at some
point, but no one has even asked for it so it''s not been a priority.
You can be guaranteed that tags are always set as soon as a class is
entered, though, so you can do those ''tagged'' tests inside the
class
definitions and be sure they behave.
At this point, as I mentioned, people aren''t really using this
functionality in Puppet, so there isn''t much around it. Your only
real option is to use if/else structures to create something like
this; there''s no boolean type in Puppet like cfengine''s
classes.
I''ve considered creating it, but you''re the first to ask for
it, so I
haven''t bothered.
--
Life isn''t fair. It''s just fairer than death,
that''s all.
-- William Goldman
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com