On 2015-08-01 21:33, Johan De Wit wrote:
> Hi,
>
> Sorry for the somewhat misleading title, but don't know better wording.
>
> Is it possible to access special variables that are set outside the
> function ? I'm not talking about config settings, but looking at
> something like
> a variable that I could query to get the filename of the manifest that
> is calling the function.
>
No, that is not generally available.
For the new Function API (new in Puppet 4.0, and avail when using
parser=future) we want to add support for things like this. We already
have the mechanism in place for injecting additional parameters into a
function calls in the new API, but no support for file/line of caller yet.
See
https://tickets.puppetlabs.com/browse/PUP-2769
> Background is the create_resources that is not filling the
> resource.file and resource.line, which makes catalog-diff not
> recognize the resource as a 'resource', thus giving false reports.
One way to avoid this problem is also to use the new resource Puppet 4.0
syntax (available in future parser as well in 3x) for resource creation
that makes it as powerful as the create_resources function call. That
way, the resource creation is done by the language and the file line
information is included.
e.g.
Resource[$the_type] {
# this part can be omitted if defaults were not used in the
create_resource call
default: * => $defaults_hash;
# The $title can naturally be an array if the same attributes
# should be applied to multiple resources.
# Use iteration around the entire resource expression to create
# a sequence of resources with different attributes
$title: * => $attributes_hash;
}
Hope that helps.
Regards
- henrik
--
Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/