Ask Your Question
0

Foreman: Expand a global variable as class parameter

asked 2015-08-18 10:44:50 -0500

helge gravatar image

We use Foreman as ENC; and I define some global variables there. How can I use such a global in a class parameter and get it expanded?

Example

In manifests, this works as expected:

class myclass ($parameter = $::global_variable) {notify {'parameter is:': message => $parameter} }

Importing myclass in Foreman, the parameter looks like this

  • parameter type: string
  • value: ${$::global_variable}

When I override the value and put in the same value as sting, it results in:

Notice: /Stage[main]/Myclass/Notify[parameter is:]/message: defined 'message' as '${$::global_variable}'
edit retag flag offensive close merge delete

Comments

2

Foreman can't expand Puppet-style variables ($foo) in parameter values. It does support use of ERB, so I may be able to suggest an alternative. Where is $::global_variable defined? Is it a fact, a parameter in Foreman, or..?

domcleal gravatar imagedomcleal ( 2015-08-20 03:10:48 -0500 )edit

Thanks Dominic! ERB was what I am looking for. They are defined in foreman 'global variables'. I tried it already before but did not know one needs to use @host.params macro. For doc reasons I will write an answer below.

helge gravatar imagehelge ( 2015-08-20 05:15:43 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-08-20 05:27:51 -0500

helge gravatar image

updated 2015-08-20 05:28:40 -0500

Thanks to domcleal comment it is clear now Foreman can not expand puppet variables directly. I will answer my own question here for documentation reasons:

As a workaround ERB templates can be used in class parameters. If global variables are defind in foreman, like in my case, one can to use the @host.params macro. Finally, setting this parameter in Foreman to my class myclass works as expected:

<%= @host.params['global_variable'] %>

Now resulting in a puppet output:

Notice: his is a foreman global variable
Notice: /Stage[main]/Myclass/Notify[parameter is:]/message: defined 'message' as 'this is a foreman global variable'
edit flag offensive delete link more

Comments

domcleal gravatar imagedomcleal ( 2015-08-20 05:40: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

2 followers

Stats

Asked: 2015-08-18 10:44:50 -0500

Seen: 2,215 times

Last updated: Aug 20 '15