Reputation: 1401
I'm pretty new to puppet, and I've got stuck on how to notify a class with a parameter. I'm trying to notify a class that I found, which runs update-rc.d with a parameter:
define myclass::update-rc {
exec { "update-rc_${title}":
command => "update-rc.d ${title} defaults",
cwd => "/tmp",
path => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:",
refreshonly => true
}
}
And the class that I wish to notify it from:
class mysecondclass {
file { '/etc/init.d/myscript':
ensure => file,
notify => Class['myclass::update-rc { "myscript": } ']
}
}
It fails with the error:
Could not find dependent Exec[Myclass::update-rc { "myscript": } ] ...
It does work if I just put myclass::update-rc { "myscript": }
in the class like this:
class mysecondclass {
file { '/etc/init.d/myscript':
ensure => file,
}
myclass::update-rc { "myscript": }
}
But I kinda wanted to notify it ... Is there a way I can achieve this?
Upvotes: 0
Views: 8771
Reputation: 2199
You can notify a class several ways in puppet:
With subscribe you will need to update the exec from inside update-rc define:
exec { "update-rc_${title}":
command => "update-rc.d ${title} defaults",
cwd => "/tmp",
path => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:",
refreshonly => true,
subscribe => File['/etc/init.d/myscript'],
}
With notify you will need to update file resource:
myclass::update-rc { "myscript": }
file { '/etc/init.d/myscript':
ensure => file,
notify => Myclass::Update-rc["myscript"]
}
This is equivalent, but using chaining arrows:
file { '/etc/init.d/myscript':
ensure => file,
} ~>
myclass::update-rc { "myscript": }
Pay attention that it's a tilde there and not a normal arrow.
Also, you should update your define name from update-rc to update_rc: https://docs.puppetlabs.com/puppet/latest/reference/lang_reserved.html#classes-and-defined-types
Upvotes: 2