Reputation: 2781
I have several classes, which follow a simple structure of ensuring a package, modifying some config files, then notifying the service.
Thus I came up with a way to apply dependencies for each class in a simple manner:
Package <| |> -> File <| |> ~> Service <| |>
However, once an error occured in one class, it would also break the dependency for all other classes. Apparently the chained collection does not apply to the current class scope, but to the global scope.
Is there a way to limit it to just the current class? I don't want to go back to specifying dependencies manually per resource!
As seen in the below graph, ALL services depend on ALL files, which in turn depend on ALL packages.
--EDIT--
I came up with the idea of using tags (a class' resources are conveniently tagged with the classname), but it didn't work either - in fact it functioned as though the class was not present (after verifying by looking at the puppet dependency graph)
Below is a sample test manifest I made:
class foo {
package { 'php-fpm':
ensure => present,
}
file { '/tmp/php-fpm.log':
ensure => file,
content => "test",
}
service { 'php-fpm':
ensure => running,
}
Package <| tag == "foo" |> -> File <| tag == "foo" |> ~> Service <| tag == "foo" |>
}
class bar {
package { 'nginx':
ensure => present,
}
file { '/tmp/nginx.log':
ensure => file,
content => "test",
}
service { 'nginx':
ensure => running,
}
Package <| tag == "bar" |> -> File <| tag == "bar" |> ~> Service <| tag == "bar" |>
}
include foo, bar
Even more curiously, in the below graph, the tags basically have no effect:
Upvotes: 1
Views: 299
Reputation: 13104
The reason the tags do not work is a defect in puppet where automatic tags are not applied until after resource collectors are evaluated. In order to get this to work with tags you actually need to explicitly declare the tag on each resource.
One other way that you could get something similar is to enable Manifest Ordered Resources. This basically executed resources in the order they are in the manifest file, and will be the default behavior in future versions of puppet.
Upvotes: 1