puppet class dependencies

66 views
Skip to first unread message

David Portabella

unread,
Mar 19, 2014, 11:18:53 AM3/19/14
to puppet...@googlegroups.com
class { c2: }
class { c3: }

class c1 {
}

class c2 {
  class { c1: }
}

class c3 {
  require c2
}

c3 depends on c2 (as expected), but c3 does not depend on c1.

this issue could be fixed by adding "require c1" inside c3.

however, in a general case, I don't know what is instantiated inside c2.
what is the proper way to tell c3 to depend on all classes and resources instantiated inside c2?


José Luis Ledesma

unread,
Mar 19, 2014, 11:22:31 AM3/19/14
to puppet...@googlegroups.com

Works as expected

You have to use contain if version> 3.4 or anchor pattern
http://docs.puppetlabs.com/puppet/latest/reference/lang_containment.html

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/a227d80e-62fe-413e-bcb4-8d371fbb73b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Portabella

unread,
Mar 19, 2014, 11:56:00 AM3/19/14
to puppet...@googlegroups.com
I still don't understand much the anchor pattern.
could you please modify the previous example to use the anchor pattern?

David Portabella

unread,
Mar 19, 2014, 12:15:44 PM3/19/14
to puppet...@googlegroups.com
I've tried the anchor pattern as follows:

class { c2: }
class { c3: }

class c1 {
}

class c2 {
  class { c1: }
  anchor { 'c1_first': } -> Class['c1'] -> anchor { 'c1_last': }
}

class c3 {
  require c2
}

but still puppet apply --graph test.pp shows that c3 does not depend on c1.
so, how to apply the anchor pattern correctly (so that c3 depends on c1)?
Message has been deleted

David Portabella

unread,
Mar 19, 2014, 12:41:34 PM3/19/14
to puppet...@googlegroups.com
I've even simplified the example:

class { c2: }
class { c3: }

class c1 {
  notice "+++"
  file {'/tmp/c1.txt': ensure => present }
}

class c2 {
#  include c1
  contain c1
  notice "+++"
  file {'/tmp/c2.txt': ensure => present }
}

class c3 {
  require c2
  notice "+++"
  file {'/tmp/c3.txt': ensure => present }
}

$ puppet apply --graph test.pp

$ open -a GraphViz /Users/david/.puppet/var/state/graphs/relationships.dot 

according to relationships.dot, /tmp/c3.txt does not even depend on /tmp/c2.txt.
why??

(puppet 3.4.3 on OSX 10.9)

David Portabella

unread,
Mar 27, 2014, 9:19:54 AM3/27/14
to puppet...@googlegroups.com
My colleague Guillaume showed me a possible implementation of the anchor pattern:

class { c2: }
->
class { c3: }

class c1 {
  notice "+++"

  anchor {'before_c1':}
  ->
  file {'/tmp/c1.txt': ensure => present }
  ->
  anchor {'after_c1':}
}

class c2 {
  include c1
  notice "+++"

  anchor {'before_c2':}
  ->
  file {'/tmp/c2.txt': ensure => present }
  ->
  anchor {'after_c2':}
}

class c3 {
  notice "+++"

  anchor {'before_c3':}
  ->
  file {'/tmp/c3.txt': ensure => present }
  ->
  anchor {'after_c3':}
}

Anchor['after_c1'] -> Anchor['before_c2']
Anchor['after_c2'] -> Anchor['before_c3']

$ puppet apply --graph test.pp

$ open -a GraphViz /Users/david/.puppet/var/state/graphs/relationships.dot 


class C3 itself does not depend on class C1,
but all the resource declared in class C3 (in this case, only /tmp/file3.txt) do depend on all the resources declared on class C2 (in this case, only /tmp/file2.txt),
and transitively they depend also on all the resources declared on class C1 (in this case, only /tmp/file1.txt)


David Portabella

unread,
Mar 27, 2014, 10:53:49 AM3/27/14
to puppet...@googlegroups.com
it seems there is a bug in puppet --graph, that misses some dependencies.

so, this code actually works as expected:

class { c3: }

class c1 {
  exec { exec1: command => '/bin/echo exec1; exit 1' }
}

class c2 {
  # include c1
  contain c1
  exec { exec2: command => '/bin/echo exec2' }
}

class c3 {
  class { c2: }
  ->
  exec { exec3: command => '/bin/echo exec3; exit 1' }
}

puppet does not execute exec3 because exec1 failed (thanks to replacing include c1 by contain c1).

$ puppet apply test.pp Notice: /Stage[main]/C1/Exec[exec1]/returns: exec1
Error: /bin/echo exec1; exit 1 returned 1 instead of one of [0]
Error: /Stage[main]/C1/Exec[exec1]/returns: change from notrun to 0 failed: /bin/echo exec1; exit 1 returned 1 instead of one of [0]
Notice: /Stage[main]/C2/Exec[exec2]/returns: executed successfully
Notice: /Stage[main]/C3/Exec[exec3]: Dependency Exec[exec1] has failures: true
Warning: /Stage[main]/C3/Exec[exec3]: Skipping because of failed dependencies

Reply all
Reply to author
Forward
0 new messages