Ask Your Question
0

Best way to fix dependency cycle when adding subscribe File to service

asked 2014-08-26 22:13:08 -0600

Red Cricket gravatar image

updated 2014-08-27 00:20:11 -0600

ramindk gravatar image

Hi,

I am wondering if there is a better way to solve a "dependency cycle" problem. Here is the current scenrio I have. Given these classes:

modules/wrapdecouple/manifests/init.pp

class wrapdecouple (
   $debug  = 'only on months with R in them',
) {
 package { 'openssh':
   ensure => 'present',
 } ->

 class {'::natural::decouple':
   debug  => $debug,
 } ->

 class {'::benbova::decouple':
   debug  => $debug,
 } ->

 class {'::shemp::decouple':
   debug  => $debug,
 } 
}

modules/natural/manifests/decouple.pp

class natural::decouple (
     $debug = 'nope',
) {

  file { '/tmp/natural.tmp':
    ensure  => file,
    path    => '/tmp/natural.tmp',
    content => $debug,
  } ->

  service { 'ntpd':
    ensure  => running,
    enable => true,
  } 
}

modules/benbova/manifests/decouple.pp

class benbova::decouple (
   $debug,
) {
 exec { "mkdir_/tmp/debugger":
   command => "/bin/mkdir -p /tmp/debugger",
   unless => "/usr/bin/test -e /tmp/debugger",
 } ->

 file { '/tmp/benbova-decouple.debug':
   ensure  => file,
   content => $debug
 } ->

 # 
 # this is where I needed to add the subscribe File
 # 
 service { 'smoke-benbova-decouple':
   ensure  => running,
   enable  => true,
   subscribe => [
                  File['/etc/sysconfig/smoke-benbova-decouple'],
                ]
  }
}

modules/shemp/manifests/decouple.pp

class shemp::decouple (
   $debug,
) {

  package { 'xfsprogs':
    ensure => 'present',
    name   => 'xfsprogs',
  } ->

  file { "/etc/sysconfig/smoke-benbova-decouple":
    ensure  => file,
    path    => "/etc/sysconfig/smoke-benbova-decouple",
    owner   => root,
    group   => root,
    mode    => '0644',
    content => $debug
  } 
}

and given this command line ... puppet apply -e 'include wrapdecouple'

... I get this predictable error ...

Notice: Compiled catalog for ost-dev-00.example.com in environment production in 0.89 seconds
Error: Could not apply complete catalog: Found 1 dependency cycle:
(File[/etc/sysconfig/smoke-benbova-decouple] => Service[smoke-benbova-decouple] => Class[BenBova::Decouple] => Class[Shemp::Decouple] => File[/etc/sysconfig/smoke-benbova-decouple])
Try the '--graph' option and opening the resulting '.dot' file in OmniGraffle or GraphViz
Notice: Finished catalog run in 0.28 seconds

The quick fix I usually put in situation like this is remove the dubious "->" resource ordering in class wrapdecouple like so ...

modules/wrapdecouple/manifests/init.pp

class wrapdecouple (
   $debug                                = 'only on months with R in them',
) {

  package { 'openssh':
    ensure => 'present',
  } ->

  class {'::natural::decouple':
    debug => $debug,
  } ->

  class {'::benbova::decouple':
    debug => $debug,
  }  -> # causes dependency cycle

 class {'::shemp::decouple':
   debug => $debug,
  } 
}

But I was wondering if there is something else I could do? Something like ...

modules/benbova/manifests/decouple.pp

class benbova::decouple (
   $debug,
) {

  exec { "mkdir_/tmp/debugger":
    command => "/bin/mkdir -p /tmp/debugger",
    unless => "/usr/bin/test -e /tmp/debugger",
  } ->

  file { '/tmp/benbova-decouple.debug':
    ensure  => file,
    content => $debug
  } ->

 # 
 # this is where I needed to add the subscribe File
 # 
 service { 'smoke-benbova-decouple':
   ensure  => running,
   enable  => true,
   subscribe => [
                  ::shemp::decouple::File['/etc/sysconfig/smoke-benbova-decouple'],
                ]
  }
}

But that gives a syntax error. The reason I ask is I know the person that originally wrote this code is very beholden to resource ordering and I do not want to get into an argument them, and if I do get into an argument I want to know what is the best way to fix this particular situation.

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-08-27 00:34:03 -0600

ramindk gravatar image

Note: It's hard to make a suggestion when your classes have ridiculous names and the code does useless tasks. Best to use the real code so we can infer what you're trying to do. shemp, benbova, mkdir tmp/something, etc make this code hard to understand and annoying to read.

Your fix even if it was syntactically correct still would not resolve that dependency cycle. The relationship to File['/etc/sysconfig/smoke-benbova-decouple'], won't change unless you remove parts of the relationship. Trying to reference by something odd or trying to be more specific won't help.

Your best bet is to restructure your modules. A module should be mostly self-contained. Why should ssh have a dependency on ntp? Why should service smoke-whatever depend on a file in a different class? Why should installing the ssh package be at the beginning of this whole mess. Make it define and part of the class that contains the server. Think of how puppetlabs-apache and other puppetlabs modules are structured and base your own modules off the way those modules are organized.

edit flag offensive delete link more

Comments

sorry I was getting bored with foo and bar. :)

Red Cricket gravatar imageRed Cricket ( 2014-08-27 11:01:57 -0600 )edit

foo and bar aren't any better. It's always best to use your real code whenever possible because it allows people with more Puppet and sysadmin experience to see what you're trying to accomplish. If you really want to talk about a corner case it's best to build the smallest/simplest version of it.

ramindk gravatar imageramindk ( 2014-08-27 11:25:19 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-08-26 22:13:08 -0600

Seen: 3,736 times

Last updated: Aug 27 '14