Ask Your Question
0

Parameter inheritance

asked 2015-08-05 15:46:15 -0500

R gravatar image

updated 2015-08-05 15:49:42 -0500

I have a puppet module which has 3 files init.pp, params.pp and config.pp. I have a few parameters that I pass via the GUI, however I need to read one parameter from the params.pp. How do I go about achieving it, so far I've done this:

The variables $userid and $groupname are passed via the Puppet console (GUI), $hostname needs to be read from params.pp.

Here is the init.pp

 class cm_poc ($userid = user", $group_name="user group", $host_name = $cm_poc::params::hostnm) inherits cm_poc::params
  {
   if $::osfamily == 'RedHat'
  {
      include cm_poc::config
 }
 }

config.pp

class cm_poc::config inherits cm_poc
 {
  $user_id = $cm_poc::user_id
  $group_name = $cm_poc::group_name
  $hostnm = $cm_poc::params::hostnm

 notify { 'host_name':
  message => "Hostname is ${hostnm}. Username Name is ${user}, group name is ${group_name}."
  }

the ouput of the above is:

Notify[host_name]/message: defined 'message' as 'Hostname is . Username Name is root, group name is root'

So from the above output, it is evident the code taking the parameters from the GUI, but not reading from the params.pp. How can I pass the parameters from both (GUI and params.pp)? Please let me know. Thanks R

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-08-05 16:35:55 -0500

helge gravatar image

updated 2015-08-05 16:42:11 -0500

I think your class cm_proc::config needs to inherit the cm_poc::params class as well or include the init class, witch inherits the params class; or or reference the init variable $cm_poc::host_name

class cm_poc::config inherits cm_poc::params
{
...
}

Otherwise your config class will not know about this variable.

Note

IMHO using class inheritance, even the ::parms class, is outdated. You should avoid it when possible. If you do not need compatibility with pre hiera puppet (puppet < 2.7) then you can just go with hiera auto parameter lookup. You can still use your ENC; variables defined there do overwrite hiera.

HTH

edit flag offensive delete link more

Comments

@helge even after adding class cm_poc::config inherits cm_poc::params, I get the hostname as blank cm_poc::Config/Notify[host_name]/message: defined 'message' as 'Hostname is .

R gravatar imageR ( 2015-08-05 17:44:53 -0500 )edit

Can you edit your question and add the params class as well? Also, can you make sure your ENC does not overwrite $hostnm? Further, does 'puppet apply -e "include cm_poc"' work as expected?

helge gravatar imagehelge ( 2015-08-05 19:04:53 -0500 )edit

@helge Thanks a lot. I am not using External Node Classifer. "does 'puppet apply -e "include cm_poc"' work as expected?" -- I cant bypass puppet master because a few parameters are fed through the GUI.

R gravatar imageR ( 2015-08-05 19:24:56 -0500 )edit

Hm, I think by definition Puppet Console is an ENC? Btw, can you explain this in more detail? Do you mean PE Console? I'd suggest you modify the class to work standalone; all you need to do is to copy the code from your question anyway ;) (and add the params class)

helge gravatar imagehelge ( 2015-08-06 03:41:39 -0500 )edit

@helge thanks a lot. I didnt know ENC is the console. I fixed the issue by migrating the content of params.pp (which is the hostname) to hiera.

R gravatar imageR ( 2015-08-06 19:24:06 -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-08-05 15:46:15 -0500

Seen: 870 times

Last updated: Aug 05 '15