diff options
| author | Brice Figureau <brice-puppet@daysofwonder.com> | 2009-05-31 15:38:14 +0200 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2009-06-10 15:28:21 +1000 |
| commit | b5a8c4db028c69793c1c9172adca4d9930c8cd1d (patch) | |
| tree | c88e3776255d34385328ac4df9b23897015225ff /lib/puppet/parser | |
| parent | 74730df475f21848027a4d2dda9ab849d3038c49 (diff) | |
| download | puppet-b5a8c4db028c69793c1c9172adca4d9930c8cd1d.tar.gz puppet-b5a8c4db028c69793c1c9172adca4d9930c8cd1d.tar.xz puppet-b5a8c4db028c69793c1c9172adca4d9930c8cd1d.zip | |
Fix #1907 (or sort) - 'require' puppet function
This function acts exactly as the 'include' function, but also
adds an ordering relation between the included class and the class
where the require function is.
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'lib/puppet/parser')
| -rw-r--r-- | lib/puppet/parser/functions/require.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/require.rb b/lib/puppet/parser/functions/require.rb new file mode 100644 index 000000000..7d73831b8 --- /dev/null +++ b/lib/puppet/parser/functions/require.rb @@ -0,0 +1,34 @@ +# Requires the specified classes +Puppet::Parser::Functions::newfunction(:require, + :doc =>"Evaluate one or more classes, adding the required class as a dependency. + +The relationship metaparameters work well for specifying relationships +between individual resources, but they can be clumsy for specifying +relationships between classes. This function is a superset of the +'include' function, adding a class relationship so that the requiring +class depends on the required class. + +.. Warning:: + using require in place of include can lead to unwanted dependency cycles. + For instance the following manifest, with 'require' instead of 'include' + would produce a nasty dependence cycle, because notify imposes a before + between File[/foo] and Service[foo]:: + + class myservice { + service { foo: ensure => running } + } + + class otherstuff { + include myservice + file { '/foo': notify => Service[foo] } + } + +") do |vals| + send(:function_include, vals) + vals = [vals] unless vals.is_a?(Array) + + # add a relation from ourselves to each required klass + vals.each do |klass| + compiler.catalog.add_edge(resource, findresource(:class, klass)) + end +end |
