Ask Your Question

Access to define resource variables?

asked 2015-12-06 15:34:37 -0500

dbschofield gravatar image

I often find that I want/need to reference a variable value declared by a define. For example the value of $home in the below snippet.

define example(
  $home = "${install_dir}/some/path/${title}"


In the code I typically already know the title and type of a resource for which I want to know the $home value. What I would really like to do is reference the resource $home value using the type and title similar to what is done with resource dependencies. Something like:


Of course puppet errors with the above syntax. But it brings me to my question... Is there a way to reference resource variable values of instantiated defines?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2015-12-07 10:18:55 -0500

hope I'm not misunderstanding whgat you're asking - if I am just shout!

have a look at puppetlabs stdlib module (can install using puppet module install puppetlabs-stdlib)

then use the function getparam (getparam/stdlib)

simple example would be from the documentation:

    define example_resource($param) {
 example_resource { "example_resource_instance":
  param => "param_value"
 getparam(Example_resource["example_resource_instance"], "param")

Cheers Stuart

edit flag offensive delete link more


I always avoided dependencies on other modules. This may be the one exception. Thanks.

dbschofield gravatar imagedbschofield ( 2015-12-14 13:51:36 -0500 )edit

answered 2016-08-15 16:38:10 -0500

The future parser allows the following.

$x = Example_resource['example_resource_instance']['param']

latest puppet docs on „resource references“  § „accessing attribute values“

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: 2015-12-06 15:34:37 -0500

Seen: 238 times

Last updated: Aug 15 '16