custom function and special variables

16 views
Skip to first unread message

Johan De Wit

unread,
Jan 8, 2015, 3:33:50 PM1/8/15
to puppe...@googlegroups.com
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.

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.

Grts

johan

--
Johan De Wit

Open Source Consultant

Red Hat Certified Engineer (805008667232363)
Puppet Certified Professional 2013/2014 (PCP0000006)
blog : http://johan.koewacht.net/
_________________________________________________________

Open-Future Phone +32 (0)2/255 70 70
Zavelstraat 72 Fax +32 (0)2/255 70 71
3071 KORTENBERG Mobile +32 (0)474/42 40 73
BELGIUM http://www.open-future.be
_________________________________________________________


Next Events:
Zabbix Certified Training | http://www.open-future.be/zabbix-certified-specialist-training-5th-till-7th-january
Zabbix Certified Professional | http://www.open-future.be/zabbix-certified-professional-training-8th-till-9th-janaury
Bacula Administrator 1 | http://www.open-future.be/bacula-administrator-i-training-13th-till-15th-january
Puppet Fundamentals | http://www.open-future.be/puppet-fundamentals-training-26th-till-28th-january
Puppet Architect | http://www.open-future.be/puppet-architect-training-29th-till-30th-january
Subscribe to our newsletter | http://eepurl.com/BUG8H

Henrik Lindberg

unread,
Jan 9, 2015, 9:57:57 AM1/9/15
to puppe...@googlegroups.com
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/


Reply all
Reply to author
Forward
0 new messages