Brian Pitts
2011-Jan-05 04:31 UTC
[Puppet Users] Including class if another isn''t included
Hi,
I''m curious how people handle the following situation in their node
definitions- you have a default configuration of a service that you want
on all of your servers except for the servers that have a more specific
configuration. For example, I want all of my servers to include the
sendmail::satellite class, except for one server where I include the
sendmail::relay class. I already had a node definition that was at the
bottom of the inheritance hierarchy for all my nodes, so adding a test
like the one below seemed like a straightforward way of accomplishing this.
node basenode {
if tagged(sendmail::relay) {
crit("$hostname is a sendmail relay")
} else {
crit("$hostname is NOT a sendmail relay")
include sendmail::satellite
}
}
node foo inherits basenode {
include sendmail::relay
}
In Puppet 0.24.8, this results in "(Scope(Node[basenode])) foo is NOT a
sendmail relay"
--
Brian Pitts
Systems Administrator | EuPathDB Bioinformatics Resource Center
706-542-1447 | bdp@uga.edu | http://eupathdb.org
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
luke.bigum
2011-Jan-05 09:10 UTC
[Puppet Users] Re: Including class if another isn''t included
Hi Brian, On Jan 5, 4:31 am, Brian Pitts <b...@uga.edu> wrote:> I''m curious how people handle the following situation in their node > definitions- you have a default configuration of a service that you want > on all of your servers except for the servers that have a more specific > configuration. For example, I want all of my servers to include the > sendmail::satellite class, except for one server where I include the > sendmail::relay class. I already had a node definition that was at the > bottom of the inheritance hierarchy for all my nodes, so adding a test > like the one below seemed like a straightforward way of accomplishing this. > > node basenode { > if tagged(sendmail::relay) { > crit("$hostname is a sendmail relay") > } else { > crit("$hostname is NOT a sendmail relay") > include sendmail::satellite > } > > } > > node foo inherits basenode { > include sendmail::relay > > }I''ve tried to do what you''re trying to do before and I found it quite messy. Using the tagged() function for classes will work, but I still ran into problems with Puppet and the order in which it''s classes and resources were declared. I got it working using stages, making sure that all my classes that were dependent on if() clauses were in a stage before the classes actually running the if() clauses. It was a real pain. In the end I scrapped the whole idea and approached from a different angle. Running with your example, every server is a Sendmail satellite, so it''ll have some File["sendmail.mc"] resource. Since that is your base standard, why not have a child class to override the behaviour of satellite to have relay functionality like so (renamed the classes to make the name space more sensible): class sendmail { file { "/etc/mail/sendmail.mc": ensure => present, source => "foo", } } class sendmail::relay inherits sendmail { File["/etc/mail/sendmail.mc"] { source => "bar", } } node basenode { include sendmail } node relay inherits basenode { include sendmail::relay } -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2011-Jan-05 14:29 UTC
[Puppet Users] Re: Including class if another isn''t included
On Jan 4, 10:31 pm, Brian Pitts <b...@uga.edu> wrote:> I''m curious how people handle the following situation in their node > definitions- you have a default configuration of a service that you want > on all of your servers except for the servers that have a more specific > configuration. For example, I want all of my servers to include the > sendmail::satellite class, except for one server where I include the > sendmail::relay class.If you want to approach the problem in that way (this class or that class) then a straightforward approach would be node basenode { if $hostname = "foo" { include sendmail::relay } else { include sendmail::satellite } } In other words, tell Puppet what to do instead of trying to make it figure it out obliquely. Alternatively, if you can enumerate or match all your hostnames then you might find something like this more appealing: node basenode { # no sendmail::* here } node relay inherits basenode { include sendmail::relay } node foo, bar, baz, ... inherits basenode { include sendmail::satellite } That doesn''t work very well if you want to draw such distinctions for several features, however. Another alternative, closer in spirit to the first, above, would be to use an external node classifier. Yet another alternative would be to use class inheritance: this is exactly the sort of scenario for which that is suited. In that case, you might have something like this: class sendmail::satellite { # whatever } class sendmail::relay inherits sendmail::satellite { # Override resources from sendmail::satellite # as appropriate # Declare additional resources as needed } node basenode { include sendmail::satellite } node foo inherits basenode { include sendmail::relay # Including both base and derived classes is harmless. # The result is the same as if only the derived were # included. } If sendmail::relay does not need to override anything in sendmail::satellite then class inheritance is not needed. In that case, have sendmail::relay "include" sendmail::satellite instead of inheriting from it, and everything else can be the same. HTH, John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.