Ask Your Question

set "global" variable from custom function

asked 2015-05-13 08:17:33 -0600

jondoe gravatar image


I have a custom function that performs some complicated processing on a map that i get from a hiera conf. After the processing is done, let us suppose that the result is stored in an array and returned to the calling recipe(in this case a class i defined). Is there a way to make the return array available to other classes/recipes(other than the one that called the custom function that is). If you think my approach is not puppet-complaint please advise on the best way to perform what I am after.


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-05-14 22:48:17 -0600

GregLarkin gravatar image

Say your variable is created by a function call like so:

class myclass {
  $myvar = myfunction(hiera('complexkey'))

  # Do some stuff here

Other classes can access the variable in the class by using $myclass::myvar to refer to it. Have a look at for more details.

edit flag offensive delete link more


it works, thanks for your answer.

jondoe gravatar imagejondoe ( 2015-05-18 04:25:56 -0600 )edit

Great, glad to hear it!

GregLarkin gravatar imageGregLarkin ( 2015-05-18 16:49:33 -0600 )edit

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-05-13 08:17:33 -0600

Seen: 1,409 times

Last updated: May 14 '15