Ask Your Question

calling_class_path and inheritance of classes

asked 2017-03-21 11:24:28 -0500

rssh22 gravatar image

updated 2017-03-21 11:59:49 -0500

In an scenario with 2 classes: pk1::claseA and pk::1claseB

with claseA like:

pk1::claseA {
$somevariable = hiera('myvariable')

and claseB like:

pk1::claseB inherits pk1::claseA {}

with the tree dir for the module pk1:


and a node like:

node 'pilot' {
  include claseB

and a hiera.yaml like:

  - yaml
  - "domains/%{calling_class_path}"
  - common

# datadir is empty here, so hiera uses its defaults:
# - /etc/puppetlabs/code/environments/%{environment}/hieradata on *nix
# - %CommonAppData%\PuppetLabs\code\environments\%{environment}\hieradata on Windows
# When specifying a datadir, make sure the directory exists.

and a file /etc/puppetlabs/code/environments/production/hieradata/domains/pk1/claseA.yaml with the content:

myvariable = 'A'

and a file /etc/puppetlabs/code/environments/production/hieradata/domains/pk1/claseB.yaml with the content:

myvariable = 'B'

$somevariable should be resolved to 'A' or to 'B' ?

In the tests I've ran the answer is A but I don't really know if I'm doing something wrong or it is the expected behaviour.

Thanks in advance!

edit retag flag offensive close merge delete


Don't use inheritance. See the note “Aside: When to Inherit” at

Kai Burghardt gravatar imageKai Burghardt ( 2017-03-22 00:10:55 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2017-03-22 05:30:26 -0500

Henrik Lindberg gravatar image

updated 2017-03-22 05:36:48 -0500

Don't use calling_class_path

The correct answer is that the logic evaluated as default value expressions are neither in the scope of the caller nor in the scope of the called - it only has access to global variables and what is already evaluated in the very small so called "parameter scope" of that particular call. The calling_class_path is therefore undefined - it just happens to work one way out of luck/chance. The concept of "calling class path" is deprecated and will be removed in the future.

Also note that the result may be different depending on the version of Puppet being used. There were bugs in puppet versions earlier than the introduction of the "parameter scope" in Puppet 4.4.0 (See PUP-1985) that made the logic evaluate in the caller's scope.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-03-21 11:24:28 -0500

Seen: 33 times

Last updated: Mar 22