Ask Your Question
0

i am newbie to puppet, have requirement to do write class to define parameter in param.pp and inherit this to other class, can someone help me with some examples

asked 2016-05-25 23:21:00 -0500

srshukla3 gravatar image

My pramas.pp- class mcpsl::params ( ) { #define Dev env parameters
$wlsadmint3url = "t3://dmcpa22z.unix.anz:33720" $wlsadmin = "weblogic" }

my init.pp -

class mcpsl ( $adminURL = $mcpsl::params::$wlsadmint3url $adminUserName = $mcpsl::params::$wlsadmin ) inherits mcpsl::params { t3URL { $wlsadmint3url: ensure => present } adminUserName { $wlsadmin: ensure => present } }

but init.pp class is not loading in puppet console due to some syntax error, any help ?

Thanks

edit retag flag offensive close merge delete

Comments

Can you give us the output of the puppet parser validate command?

UBPClaw gravatar imageUBPClaw ( 2016-05-26 17:24:13 -0500 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2016-05-29 22:14:42 -0500

srshukla3 gravatar image

Hi,

While running the above code, i am getting below error -

Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Missing title. The title expression resulted in undef at /etc/puppetlabs/puppet/environments/msl_test/modules/mcpsl/manifests/init.pp:25:11 on node abc.vic.au.anz

line 25 is - t3URL { $wlsadmint3url: , not how to specify a default value or can i just use -

inherits mcpsl::params { t3URL { $wlsadmint3url } adminUserName { $wlsadmin } }

instead of - inherits mcpsl::params { t3URL { $wlsadmint3url: ensure => present } adminUserName { $wlsadmin: ensure => present }

I am not very clear on how to define the parameter after inherits ..?

Thanks

edit flag offensive delete link more
0

answered 2016-05-26 20:48:31 -0500

DarylW gravatar image

I copy/pasted your code as is into a folder

ubuntu:~$ tree modules/mcpsl/
modules/mcpsl/
└── manifests
    ├── init.pp
    └── params.pp

1 directory, 2 files

running puppet parser validate on each of the files.

ubuntu:~$ puppet parser validate ~/modules/mcpsl/manifests/init.pp
Error: Could not parse for environment production: Illegal fully qualified name at /home/xxx/modules/mcpsl/manifests/init.pp:3:31
ubuntu:~$ puppet parser validate ~/modules/mcpsl/manifests/params.pp
ubuntu:~$

That is telling us line 3, char 31 is where the parse error is at. Looking into reformating the file (but not changing the syntax) We'll see what the code looks like.

# init.pp
class mcpsl (
  $adminURL = $mcpsl::params::$wlsadmint3url 
  $adminUserName = $mcpsl::params::$wlsadmin 
) inherits mcpsl::params { 
  t3URL { $wlsadmint3url: 
    ensure => present 
  }
  adminUserName { $wlsadmin: 
    ensure => present 
  }
}

Rerunning puppet parser validate, it gives us the same error. There are several things that stand out to me. I am assuming you are using some preexisting module with a resource type / define for t3URL and a type/resource of adminUserName.

The first error is due to you trying to use a fully qualified variable, but you included a $ before the name of the variable you were referencing. If we fix that..

  $adminURL = $mcpsl::params::wlsadmint3url
  $adminUserName = $mcpsl::params::wlsadmin

ubuntu:~$ puppet parser validate ~/modules/mcpsl/manifests/init.pp
Error: Could not parse for environment production: Syntax error at 'adminUserName' at /home/xxx/modules/mcpsl/manifests/init.pp:4:3

Looking closer, it appears that we are missing the comma required between parameters (you also are able to leave trailing commas to make future refactoring easier, and have less messy diffs in your version control)

After fixing the $ in the fully qualified name and the missing comma, puppet parser validate doesn't complain.

Here is the final version that I had in place

# init.pp
class mcpsl (
  $adminURL = $mcpsl::params::wlsadmint3url,
  $adminUserName = $mcpsl::params::wlsadmin,
) inherits mcpsl::params {
  t3URL { $wlsadmint3url:
    ensure => present
  }
  adminUserName { $wlsadmin:
    ensure => present
  }
}

You also should use an IDE/plugin like geppetto, the plugin for netbeans, IntelliJ, or any of the other offerings. They will help with syntax highlighting, warning/error notifications (yellow/red underlines) with syntax errors, and suggestions on how to fix your code, along with deprecation warnings.
You also can install the puppet-lint ruby gem, and run puppet-lint /path/to/my.pp to help guide your code acording to the official style guide.

edit flag offensive delete link more

Comments

Thanks for detail explanation, it helps me a lot in my learning on Puppet.

srshukla3 gravatar imagesrshukla3 ( 2016-05-29 07:00:27 -0500 )edit

Hi, While running the above code, i am getting below error - Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Missing title. The title expression resulted in undef at /etc/puppetlabs/puppet/environm

srshukla3 gravatar imagesrshukla3 ( 2016-05-29 22:14:32 -0500 )edit

You are trying to use the variable $adminURL as the title of your t3URL resource. Does that actually contain a value? The error message makes me think that it is undef. Do you have a typo somewhere, either in the default value from params.pp or in your above class? If you use an IDE, it ..

DarylW gravatar imageDarylW ( 2016-05-30 15:24:34 -0500 )edit

.. should show you if you are using an undeclared variable, and code navigation would let you get from point a to point b. without having the code in front of me, I can't diagnose it beyond that. I would try putting in notify statements where appropriate. Is the module avail on the forge?

DarylW gravatar imageDarylW ( 2016-05-30 15:26:18 -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: 2016-05-25 23:18:55 -0500

Seen: 611 times

Last updated: May 29 '16