Also see these for interesting ideas:
http://www.craigdunn.org/2012/05/239/
http://garylarizza.com/blog/2014/02/17/puppet-workflow-part-1/
http://garylarizza.com/blog/2014/02/17/puppet-workflow-part-2/
In your place, this is how I would arrange what you want, because I often cram
configs together (huzzah legacy systems):
class testmod::packages {
package { 'nginx': }
}
class testmod::services {
service { 'nginx':
ensure => running,
enable => true,
}
}
class testmod::nginxtest {
file { '/tmp/nginx.test': }
}
# you might also look into "contain" over "include"?
class testmod {
include ::testmod::packages
include ::testmod::services
Class['::testmod::packages'] ~> Class['::testmod::services']
}
# this shows how a generic testmod is all normal-ish...
class profile::testmod {
include ::testmod
}
# ...but a testmod nginx tester is a bit special
# obviously you could move includes/chaining around
class profile::testmodnginx {
include ::testmod::packages
include ::testmod::services
include ::testmod::nginxtest
Class['::testmod::packages'] ~> Class['::testmod::services']
Class['::testmod::packages'] -> Class['::testmod::nginxtest']
Class['::testmod::nginxtest'] ~> Class['::testmod::services']
}
Or you could do it in a parameterized fashion:
class testmod ( $nginxtest = false ) {
package { 'nginx': }
# from stdlib, see puppet forge
if str2bool($nginxtest) {
file { '/tmp/nginx.test':
ensure => present,
require => Package['nginx'],
notify => Service['nginx'],
}
}
service { 'nginx':
ensure => running,
enable => true,
}
}
Then in hiera:
testmod::nginxtest: true
And somewhere else:
include testmod
Or the declarative way, having a higher chance of hurting you later:
class { 'testmod':
nginxtest => true,
}
Or you could do it any way you wanted, really.
(Cue zillions of different posts about the right way to do this.)
On Wed, Jun 18, 2014 at 06:22:00PM +0400, Sergey Arlashin wrote:
> Hm, ok.
> But when I use 'subscribe' instead of 'notify'
>
> class testmod {
> package { 'nginx': ensure => installed }
> service { 'nginx':
> ensure => running,
> enable => true,
> require => Package['nginx'],
> subscribe => File['/tmp/nginx.test']
> }
> }
> class testmod::nginxtest {
> file { '/tmp/nginx.test':
> ensure => present
> }
> }
>
> I get
>
> ==> test-node: Error: Could not apply complete catalog: Found 1 dependency
> cycle:
> ==> test-node: (File[/tmp/nginx.test] => Service[nginx] => Class[Testmod] =>
> Class[Testmod::Nginxtest] => File[/tmp/nginx.test])
> ==> test-node: Try the '--graph' option and opening the resulting '.dot' file
> in OmniGraffle or GraphViz
>
> I do need to have 2 separate modules. I need the class 'testmode' to run
> before class 'test mod::nginxtest'. And I need to restart service 'nginx'
> when I change '/tmp/nginx.test'.
>
> So then the question is - how to do this properly? Do I need to create
> something like exec { 'nginx restart': ... } ?
>
>
> On Jun 18, 2014, at 5:55 PM, Felix Frank <[email protected]>
> wrote:
>
> > Hi,
> >
> > On 06/18/2014 03:51 PM, Sergey Arlashin wrote:
> >> Could you please help me figure out why this is happening ? It seems there
> >> is nothing in test mod whih requires testmod::nginxtest .
> >
> > actually yes, there is.
> >
> > file { '/tmp/nginx.test':
> > ensure => present,
> > notify => Service['nginx'];
> > }
> >
> > The 'notify' implicitly puts File['/tmp/nginx.test'] *before*
> > Service['nginx'].
> >
> > The
> >
> > class { 'testmod::nginxtest':
> > require => Class['testmod']
> > }
> >
> > ends up doing the opposite - wanting the Service['nginx'] before
> > File['/tmp/nginx.test'].
> >
> > HTH,
> > Felix
> >
> > --
> > 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 [email protected].
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/puppet-users/53A19A45.30903%40alumni.tu-berlin.de.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/9548D943-73FE-41B1-984C-1EDC8FAD40D3%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/20140618150053.GA27009%40iniquitous.heresiarch.ca.
For more options, visit https://groups.google.com/d/optout.