David Schmitt wrote:
> chakkerz wrote:
>> Hello there
>>
>> I'm having a problem (again). At my site we are maintaining RHEL,
>> CentOS and Solaris hosts, with in the future possibly some FreeBSD
>> also being added into the mix. To this end instead of constantly
>> branching whenever running a command on the console (or remembering
>> where it is located), I've set all the commands we need so far up in
>> the default node:
>>
>> class defaultnode
>> {
>>         if ($httpd_group == "")
>>         {
>>                 $httpd_group = "root"
>>         }
>>
>>         case $operatingsystem
>>         {
>>                 centos, redhat:
>>                 {
>>                         $cat_cmd        = "/bin/cat"
>>                         $chkconfig_cmd  = "/sbin/chkconfig"
>>                         $chown_cmd      = "/bin/chown"
>>                         $chmod_cmd      = "/bin/chmod"
>>                         $echo_cmd       = "/bin/echo"
>>                         $grep_cmd       = "/bin/grep"
>>                         $ln_cmd         = "/bin/ln"
>>                         $ls_cmd         = "/bin/ls"
>>                         $mailx_cmd      = "/bin/mailx"
>>                         $newaliases_cmd = "/usr/bin/newaliases"
>>                         $rm_cmd         = "/bin/rm"
>>                         $sed_cmd        = "/bin/sed"
>>                         $tar_cmd        = "/bin/tar"
>>                         $touch_cmd      = "/bin/touch"
>>                         $wget_cmd       = "/usr/bin/wget"
>>
>>                         include redhat-default
>>                 }
>>                 solaris:
>>                 {
>>                         $cat_cmd        = "/usr/bin/cat"
>>                         $chown_cmd      = "/usr/bin/chown"
>>                         $chmod_cmd      = "/usr/bin/chmod"
>>                         $echo_cmd       = "/usr/bin/echo"
>>                         $grep_cmd       = "/usr/bin/grep"
>>                         $mailx_cmd      = "/usr/bin/mailx"
>>                         $newaliases_cmd = "/usr/sbin/newaliases"
>>                         $rm_cmd         = "/usr/bin/rm"
>>                         $tar_cmd        = "/usr/sfw/bin/gtar"
>>
>>                         include solaris-default
>>                 }
>>                 default:
>>                 {
>>                         include shared-default
>>                 }
>>         }
>> }
>>
>> which is called by all nodes, eg:
>>
>> node "testnode.example.org"
>> {
>>         include defaultnode
>>
>>         exec
>>         { "$chkconfig_cmd snmpd on && $touch_cmd /tmp/
>> snmpd_chkconfig.USG":
>>                 cwd => "/",
>>                 creates => "/tmp/snmpd_chkconfig.USG",
>>         }
>>
>> }
>>
>> But when i run puppet the variables aren't defined:
>> err: Could not create  snmpd on &&  /tmp/snmpd_chkconfig.USG: ' snmpd
>> on &&  /tmp/snmpd_chkconfig.USG' is both unqualifed and specified no
>> search path at /etc/puppet/manifests/nodes/testnode.node:9
>> warning: Not using cache on failed catalog
>> warning: Configuration could not be instantiated: ' snmpd on &&  /tmp/
>> snmpd_chkconfig.USG' is both unqualifed and specified no search path
>> at /etc/puppet/manifests/nodes/testnode.node:9
> 
> Variables don't escape their scope. Use the search() function to add 
> "defaultnode" to the serachpath or reference the variables directly with 
> $defaultnode::chkconfig_cmd or "${defaultnode::chkconfig_cmd}". See the 
> LanguageTutorial on the wiki for details (section "Variables"[1]).

D'oh. For your actual, underlying problem it'd probably be better to use 
something like Volcane's extlookup[1][2] function:

| $extlookup_datadir = "/etc/puppet/manifests/extdata"
| $extlookup_precedence = ["%{fqdn}", "os_%{operatingsystem}", "shared"]
| $cat_cmd = extlookup('cat_cmd')

That can be done in the top-level scope (e.g. in the site.pp outside of 
any node or class) to propagate the values to all manifests and modules.

Regards, DavidS

[1]http://nephilim.ml.org/~rip/puppet/extlookup.rb
[2]http://github.com/puppet-modules/puppet-common/blob/0caa32db1aaad6dabc9542c5e0aa20e76ea94f48/plugins/puppet/parser/functions/extlookup.rb
 



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to