Ask Your Question
0

set "global" variable from custom function

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

jondoe gravatar image

Hi,

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.

Regards

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

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

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 https://docs.puppetlabs.com/guides/scopeandpuppet.html for more details.

edit flag offensive delete link more

Comments

it works, thanks for your answer.

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

Great, glad to hear it!

GregLarkin gravatar imageGregLarkin ( 2015-05-18 16:49:33 -0500 )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

Stats

Asked: 2015-05-13 08:17:33 -0500

Seen: 860 times

Last updated: May 14 '15