Well ... then I agree with your sentiments on using classes, it can
get ugly using inner classes to achieve what you want. Something I
often find myself doing with the puppetlabs-firewall module using
inner classes to get around having to do proto => tcp and proto => udp
repeatedly:
class c {
class ipt_t {
Firewall { proto => tcp, jump => "ACCEPT" }
firewall { "100 accept ssh": dport => 22 }
# ... more tcp rules ...
}
include ipt_t
class ipt_u {
Firewall { proto => udp, jump => "ACCEPT" }
firewall { "100 accept dns": dport => 53 }
# ... more udp rules ...
}
include ipt_u
}
Perhaps anonymous blocks/closures are a more flexible proposal for the
language which solves both problems? For example:
class c {
{
# Order matters
package { "a": }->
exec { "b": }
}->
{
# Order doesn't matter
package { "b": }
exec { "c": }
}
}
Then you can also use these anonymous blocks/closures with defaults as well:
class c {
{
Service { hasstatus => true }
service { "a": }
}->
{
Service { hasstatus => false }
service { "b": }
}
}
ken.
On Tue, Jul 5, 2011 at 10:26 AM, vagn scott <[email protected]> wrote:
> On 07/05/2011 04:35 AM, Ken Barber wrote:
>>
>> Whats wrong with using chained resources?
>>
>
> It doesn't scale.
>
> Try expanding this (it is a slightly improved
> proposal with block{} instead of order{}):
>
> class c {
>
> block { "x": # any order
> package { ... }
> file { "aaa": }
> exec { "bbb": }
> file { "ccc": }
> include foo
> }
> block { "y": # order matters
> $ordered => true # default is false
> file { "ddd": }
> exec { "eee": }
> include baz
> file { "fff": }
> }
> block { "z": # any order
> file { "ggg": }
> exec { "hhh": }
> file { "iii": }
> }
>
> Block[ x ] -> Block[ y ] -> Block[ z ]
>
> }
>
> meaning all resources in x before any in y, then y in sequence,
> before any in z
>
> ------------
>
> Now, you can rewrite this using class {} instead of block{}.
> You probably have lots of classes in that style, and then you
> sequence things with Class[ a ] -> Class[ b ]. How many of
> those classes only exist because there is no other block structure?
>
> I submit that if you make a class, it should be sensible to include
> it somewhere, as a class, representing something useful.
> We need blocks so we don't go around abusing classes.
>
> --
> vagn
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.