On Thursday, October 18, 2012 6:08:23 PM UTC-5, Caio Cezar Zapater de Souza
wrote:
>
> Hi,
>
> I have created a define with packages services and a mount inside, but
> when I notify the define all of them receive the notify but I want only
> refresh the mount.
> It is possible?
>
No. Instead, you need to refactor your definition. In fact, it would be a
good idea to do so even if you didn't have a problem with notifications.
See further comments below.
>
> Here is my define:
>
>
> define xmount (
> $device = undef,
> $device_base = undef,
> $device_qa = undef,
> $device_dev = undef,
> $options = "defaults",
> $options_base = undef,
> $options_qa = undef,
> $options_dev = undef,
> $path = undef,
> $atboot = true,
> $ensure = mounted,
> $fstype = undef,
> $remounts = true,
> $remounts_lazy = false,
> $dump = 0,
> $pass = 0) {
> if ($fstype = "nfs") {
> if !defined(Package["portmap"]) {
> package { "portmap": ensure => present; }
> }
>
> if !defined(Package["initscripts"]) {
> package { "initscripts": ensure => present; }
> }
>
> if !defined(Service["portmap"]) {
> service { "portmap":
> enable => true,
> ensure => running,
> hasrestart => true,
> hasstatus => true,
> subscribe => Package["portmap", "initscripts"],
> notify => Mount["${path}"];
> }
> }
>
> if !defined(Service["netfs"]) {
> service { "netfs":
> enable => true,
> ensure => running,
> hasrestart => true,
> hasstatus => true,
> subscribe => Package["portmap", "initscripts"],
> notify => Mount["${path}"];
> }
> }
> }
>
It is flat wrong to declare package and service resources inside this
definition. The notification problem you reported is only a symptom.
Another symptom is that you decided you needed to protect the package and
service declarations via 'defined'. A third symptom is that you will only
get those services notifying one Mount when you declare multiple xmount
resources.
The underlying problem is with the implied model: 'xmount' resources depend
on those other resources, but they do not *own* them. Therefore, they
should declare their dependency, not the resources themselves. You would
do that by factoring out the resource declarations into one or more
classes, and 'include'ing that class. Look to the end for an example.
>
> case $pool {
> default : {
> $deviceA = $device
> $optionsA = $options
> }
> /.*-q-prt$/, /.*-q-pla$/, /.*-qa$/ : {
> $deviceA = $device_qa
> $optionsA = $options_qa
> }
> /.*-s-prt$/, /.*-s-pla$/, /.*-stg$/, /.*-dev$/ : {
> $deviceA = $device_dev
> $optionsA = $options_dev
> }
> /.*-base$/ : {
> $deviceA = $device_base
> $optionsA = $options_base
> }
> }
>
> $device_chosed = "${deviceA}" ? {
> default => "${deviceA}",
> undef => "${device}"
> }
>
> $options_chosed = "${optionsA}" ? {
> default => "${optionsA}",
> undef => "${options}"
> }
>
> if ($device_chosed != "") {
> exec { "define_xmount_recursedir-${title}-${path}":
> command => "mkdir -p '${path}'",
> unless => "test -d '${path}'",
> cwd => "/tmp",
> logoutput => on_failure,
> path => [
> "/bin",
> "/sbin",
> "/usr/bin",
> "/usr/sbin"],
> timeout => 2;
> }
>
Although I don't think it's harmful to manage the mount point that way, I'm
having trouble seeing why you don't use a File resource. It would be a lot
simpler and clearer. I suppose the point is to automatically create parent
directories when they don't exist, but I think that's over-engineered. You
can always know what parent directories you need, and manage them as File
resources (outside the definition).
>
> mount { "${path}":
> atboot => $atboot,
> device => $mount_chosed,
> ensure => $ensure,
> fstype => $fstype,
> options => $options_chosed,
> remounts => $remounts,
> dump => $dump,
> pass => $pass,
> require => Exec["define_xmount_recursedir-${title}-${path}"];
> }
> }
> }
>
So here is my recommendation for how to approach this:
class mymodule::nfsdeps {
# no need for if !defined(...) because classes
# are singletons
package { "portmap": ensure => present; }
package { "initscripts": ensure => present; }
service { "portmap":
enable => true,
ensure => running,
hasrestart => true,
hasstatus => true,
subscribe => Package["portmap", "initscripts"],
notify => Mount["${path}"];
}
service { "netfs":
enable => true,
ensure => running,
hasrestart => true,
hasstatus => true,
subscribe => Package["portmap", "initscripts"],
notify => Mount["${path}"];
}
}
define anothermodule::xmount (
# parameters ...
) {
if ($fstype = "nfs") {
include 'mymodule::nfsdeps'
# Resources to which the mount will need to subscribe:
$subscriptions = [ Service['portmmap'], Service['netfs'] ]
}
# parameter processing ...
# the native resources of which instances
# are composed:
if ($device_chosed != "") {
file { "${path}": ensure => directory }
mount { "${path}":
# various properties ...
require => File["${path}"],
subscribe => $subscriptions
}
}
}
John
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/puppet-users/-/1u-uqedwVXsJ.
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.