Ask Your Question

Using local variables within a quoted string of Exec

asked 2013-01-31 17:43:37 -0500

typedeaf gravatar image

updated 2013-01-31 17:43:59 -0500

Here is the definition

class kdump::params {
    # there was a bug with the auto setting prior to 6.2, so don't use it on those versions.
    case $operatingsystemrelease {
        '6.0','6.1': { $grubby_param = "crashkernel=0M-2G:128M,2G-6G:256M,6G-8G:512M,8G-16G:768M,17-:896M" }
        /^6.[^01]$/: { $grubby_param = "crashkernel=auto"}
        default:     { $grubby_param = "crashkernel=128M" }
    notify {"*** $grubby_param":}                                        

And then in kdump::config I have

include kdump::params
        exec { "grubby --update-kernel=DEFAULT --args=\"${grubby_param}\"":
            path => ["/sbin", "/bin" ],
            unless => "grep -q -E \"kernel /vmlinuz-$kernelrelease .* ${grubby_param}\" /etc/grub.conf",

When it gets run, the results are $grubby_param being blank:

notice: *** crashkernel=0M-2G:128M ...
edit retag flag offensive close merge delete


typedeaf gravatar imagetypedeaf ( 2013-01-31 19:00:57 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2013-02-01 02:47:19 -0500

If your goal is solely to set kernel parameters in grub, I'd recommend you use the kernel_parameter type from the augeasproviders module. This will be much more reliable.

Also, consider using $::lsbdistrelease instead of $::operatingsystemrelease (and don't forget the :: for the variable scope or Puppet 3.0.0 will bite you).

edit flag offensive delete link more


I might try that. But I am still going to need to get a local variable in there. I am not sure if its an interpolation problem, or a scope ...(more)

typedeaf gravatar imagetypedeaf ( 2013-02-01 11:01:03 -0500 )edit

answered 2013-02-01 11:57:26 -0500

typedeaf gravatar image

Suspecting that it might be a scope issue, I made the following change:

    exec { "grubby --update-kernel=DEFAULT --args=\"${kdump::params::grubby_param}\"":
        path => ["/sbin", "/bin" ],
        unless => "grep -q -E \"kernel /vmlinuz-$kernelrelease .* ${kdump::params::grubby_param}\" /etc/grub.conf",

After making this change, the variable 'came into existence'. I do not know if that is the way you are supposed reference variables 'included' from other classes. It does not align with many examples that I have seen.

edit flag offensive delete link more

answered 2013-02-01 11:56:30 -0500

Stefan gravatar image

it does not look like an interpolation problem as I can't see an error there. But if you include a class, the variables that are defined in that class will not be present in your outer class.

You should however can reference the variable as kdump::params::grubby_param.

edit flag offensive delete link more


heh, thanks. i am 1 min ahead of you :)

typedeaf gravatar imagetypedeaf ( 2013-02-01 12:11:46 -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


Asked: 2013-01-31 17:43:37 -0500

Seen: 970 times

Last updated: Feb 01 '13