FAQ

On Wednesday, May 29, 2013 10:29:22 AM UTC-5, Fabio Sangiovanni wrote:
Hi everybody,

I'm a new puppet user, and I have a question about defined types and
relationships.

I want a defined type to be part of a module.
It manages optional configuration files, so the user can decide to declare
it one or more times or not to declare it at all.
In the case the defined type is declared, I want the contained resources
to be in relationship with other resources in my main module class; in
particular, I want the resources in the defined type to be managed *after*
package and *before* service.

Two ways come to mind:
1) embed the necessary require/before (and/or subscribe/notify) inside the
the defined type's resources:

# == Define: software::mydefinedtype
define software::mydefinedtype {
file { "/path/to/${name}":
[...]
require => Package['software'],
before => Service['software'],
}
}

2) rely on dependency chains and a resource collector in the main module
class (and of course on the containment properties of defined types):

# == Class: software
class software {
[...]
Package['software'] -> Software::Mydefinedtype <| |> ->
Service['software']
}

What is, in your opinion, the best method?
I've tried both, and both apparently work with no issues.

For this particular pattern of requirements, I strongly prefer method 1.
It keeps everything associated directly with the defined type together in
one place. I would suggest one tweak, however: the defined type should
explicitly 'include' class 'software' if it refers to resources declared by
that class. For example:

define software::mydefinedtype {
   include 'software'
   file { "/path/to/${name}":
     [...]
     require => Package['software'],
     before => Service['software'],
   }
}

Note also that if you prefer the chain operators to the metaparameters, you
can use the former in your defined type:

define software::mydefinedtype {
   include 'software'
   file { "/path/to/${name}":
     [...]
   }
     Package['software'] -> File["/path/to/${name}"] -> Service['software']
}

Indeed, I think you can even write it like this:

define software::mydefinedtype {
   include 'software'
   Package['software'] ->
   file { "/path/to/${name}":
     [...]
   } ->
   Service['software']
}


One doubt about method 2:
at http://docs.puppetlabs.com/puppet/3/reference/lang_relationships.html,
I can read:
"If one of the resources in a relationship is never declared, compilation
will fail with one of the following errors [...]"
I suppose that this doesn't apply in case of resources chained through
resource collectors, does it? I'm asking because, even without declarations
of instances of the defined type, I got no such errors.
Personally, I am uncomfortable with relying on undocumented behavior. It
may change without warning from one version of the software to another.
Even if that does not bother you, in this particular case you should also
verify that the transitively implied relationship between
Package['software'] and Service['software'] is still present when no
instances of Software::Mydefinedtype are declared. You can make puppet
generate a relationship graph to check.


John

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 4 | next ›
Discussion Overview
grouppuppet-users @
categoriespuppet
postedMay 29, '13 at 6:43p
activeJun 3, '13 at 8:33p
posts4
users3
websitepuppetlabs.com

People

Translate

site design / logo © 2021 Grokbase