diff --git a/lib/puppet/parser/functions/contain.rb b/lib/puppet/parser/functions/contain.rb index 6400f2950..9c9447661 100644 --- a/lib/puppet/parser/functions/contain.rb +++ b/lib/puppet/parser/functions/contain.rb @@ -1,35 +1,36 @@ # Called within a class definition, establishes a containment # relationship with another class Puppet::Parser::Functions::newfunction( :contain, :arity => -2, :doc => "Contain one or more classes inside the current class. If any of these classes are undeclared, they will be declared as if called with the `include` function. Accepts a class name, an array of class names, or a comma-separated list of class names. A contained class will not be applied before the containing class is begun, and will be finished before the containing class is finished. -When parser == 'future' the names will be made absolute before -being used, and `Class[name]`, or `Resource['class', name]` may also be -used as references. +When the future parser is used, you must use the class's full name; +relative names are no longer allowed. In addition to names in string form, +you may also directly use Class and Resource Type values that are produced by +the future parser's resource and relationship expressions. " ) do |classes| scope = self # Make call patterns uniform and protected against nested arrays, also make # names absolute if so desired. classes = transform_and_assert_classnames(classes.is_a?(Array) ? classes.flatten : [classes]) containing_resource = scope.resource # This is the same as calling the include function but faster and does not rely on the include # function (which is a statement) to return something (it should not). (compiler.evaluate_classes(classes, self, false) || []).each do |resource| if ! scope.catalog.edge?(containing_resource, resource) scope.catalog.add_edge(containing_resource, resource) end end end diff --git a/lib/puppet/parser/functions/include.rb b/lib/puppet/parser/functions/include.rb index a7652bf36..2bebbba8b 100644 --- a/lib/puppet/parser/functions/include.rb +++ b/lib/puppet/parser/functions/include.rb @@ -1,34 +1,35 @@ # Include the specified classes Puppet::Parser::Functions::newfunction(:include, :arity => -2, :doc => "Declares one or more classes, causing the resources in them to be evaluated and added to the catalog. Accepts a class name, an array of class names, or a comma-separated list of class names. The `include` function can be used multiple times on the same class and will only declare a given class once. If a class declared with `include` has any parameters, Puppet will automatically look up values for them in Hiera, using `::` as the lookup key. Contrast this behavior with resource-like class declarations (`class {'name': parameter => 'value',}`), which must be used in only one place per class and can directly set parameters. You should avoid using both `include` and resource-like declarations with the same class. The `include` function does not cause classes to be contained in the class where they are declared. For that, see the `contain` function. It also does not create a dependency relationship between the declared class and the surrounding class; for that, see the `require` function. -When parser == 'future' the names will be made absolute before -being used, and `Class[name]`, or `Resource['class', name]` may also be -used as references. +When the future parser is used, you must use the class's full name; +relative names are no longer allowed. In addition to names in string form, +you may also directly use Class and Resource Type values that are produced by +the future parser's resource and relationship expressions. ") do |vals| # Unify call patterns (if called with nested arrays), make names absolute if # wanted and evaluate the classes compiler.evaluate_classes( transform_and_assert_classnames( vals.is_a?(Array) ? vals.flatten : [vals]), self, false) end diff --git a/lib/puppet/parser/functions/require.rb b/lib/puppet/parser/functions/require.rb index b6193f540..d6350fc4b 100644 --- a/lib/puppet/parser/functions/require.rb +++ b/lib/puppet/parser/functions/require.rb @@ -1,60 +1,61 @@ # Requires the specified classes Puppet::Parser::Functions::newfunction( :require, :arity => -2, :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] } } Note that this function only works with clients 0.25 and later, and it will fail if used with earlier clients. -When parser == 'future' the names will be made absolute before -being used, and `Class[name]`, or `Resource['class', name]` may also be -used as references. +When the future parser is used, you must use the class's full name; +relative names are no longer allowed. In addition to names in string form, +you may also directly use Class and Resource Type values that are produced by +the future parser's resource and relationship expressions. ") do |vals| # Make call patterns uniform and protected against nested arrays, also make # names absolute if so desired. vals = transform_and_assert_classnames(vals.is_a?(Array) ? vals.flatten : [vals]) # This is the same as calling the include function (but faster) since it again # would otherwise need to perform the optional absolute name transformation # (for no reason since they are already made absolute here). # compiler.evaluate_classes(vals, self, false) vals.each do |klass| # lookup the class in the scopes if classobj = find_hostclass(klass) klass = classobj.name else raise Puppet::ParseError, "Could not find class #{klass}" end # This is a bit hackish, in some ways, but it's the only way # to configure a dependency that will make it to the client. # The 'obvious' way is just to add an edge in the catalog, # but that is considered a containment edge, not a dependency # edge, so it usually gets lost on the client. ref = Puppet::Resource.new(:class, klass) resource.set_parameter(:require, [resource[:require]].flatten.compact << ref) end end