From b5a8c4db028c69793c1c9172adca4d9930c8cd1d Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Sun, 31 May 2009 15:38:14 +0200 Subject: 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 --- lib/puppet/parser/functions/require.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lib/puppet/parser/functions/require.rb (limited to 'lib/puppet/parser') 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 -- cgit