Check Module Path

[root@machine-1 test]# puppet config print modulepath
/etc/puppet/modules:/usr/share/puppet/modules

Working Directory

[root@machine-1 test]# pwd
/etc/puppet/modules/test

params.pp

class test::params()
{
$javaCommand="/u01/app/java/bin/java"
}

wlst.pp which inherits params.pp

class wlstexec(
$javaCommand=$test::params::javaCommand,
$middlewareHome="/u01/middleware",
$scriptHome="/u01/scripts"
)inherits test::params
{
exec {'set-env':

environment => ["CLASSPATH=${middlewareHome}/wlserver/server/lib/weblogic.jar"],
command => "${javaCommand}  weblogic.WLST ${scriptHome}/puppet-test1.py",
logoutput => true,
}
}
include wlstexec

Manual execution on agent

[root@machine-1 test]# puppet apply manifests/wlst.pp
Warning: Config file /etc/puppet/hiera.yaml not found, using Hiera defaults
Notice: Compiled catalog for machine-1.emea.eu.int in environment production in 0.07 seconds
Notice: /Stage[main]/Wlstexec/Exec[set-env]/returns:
Notice: /Stage[main]/Wlstexec/Exec[set-env]/returns: Initializing WebLogic Scripting Tool (WLST) ...
Notice: /Stage[main]/Wlstexec/Exec[set-env]/returns:
Notice: /Stage[main]/Wlstexec/Exec[set-env]/returns: Welcome to WebLogic Server Administration Scripting Shell
Notice: /Stage[main]/Wlstexec/Exec[set-env]/returns:
Notice: /Stage[main]/Wlstexec/Exec[set-env]/returns: Type help() for help on available commands
Notice: /Stage[main]/Wlstexec/Exec[set-env]/returns:
Notice: /Stage[main]/Wlstexec/Exec[set-env]/returns: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Notice: /Stage[main]/Wlstexec/Exec[set-env]/returns: SCRIPT IS BEING IMPORTED IN ANOTHER MODULE AND THEN EXECUTED
Notice: /Stage[main]/Wlstexec/Exec[set-env]/returns: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Notice: /Stage[main]/Wlstexec/Exec[set-env]/returns: Puppet is running me...
Notice: /Stage[main]/Wlstexec/Exec[set-env]/returns: executed successfully
Notice: Finished catalog run in 3.43 seconds
[root@machine-1 test]#


 

This design pattern can make for significantly cleaner code while enabling some really sophisticated behavior around default values.

Another good example from puppet labs,

# /etc/puppetlabs/code/modules/webserver/manifests/params.pp

class webserver::params {
  $packages = $operatingsystem ? {
    /(?i-mx:ubuntu|debian)/        => 'apache2',
    /(?i-mx:centos|fedora|redhat)/ => 'httpd',
  }
  $vhost_dir = $operatingsystem ? {
    /(?i-mx:ubuntu|debian)/        => '/etc/apache2/sites-enabled',
    /(?i-mx:centos|fedora|redhat)/ => '/etc/httpd/conf.d',
  }
}

# /etc/puppetlabs/code/modules/webserver/manifests/init.pp

class webserver(
  String $packages  = $webserver::params::packages,
  String $vhost_dir = $webserver::params::vhost_dir
) inherits webserver::params {

 package { $packages: ensure => present }

 file { 'vhost_dir':
   path   => $vhost_dir,
   ensure => directory,
   mode   => '0750',
   owner  => 'www-data',
   group  => 'root',
 }
}