FAQ
Hello,

I'm trying to send parameters to an Exec ("exec1") based on values, using a
case statement. I've tried putting the two versions of the exec in a case
block, which failed (exec1 is a dependency of exec2, and exec2 complained
it could not find exec1), and a case statement can't go directly directly
into the parameters of the Exec itself

Google helped me with this thread:
http://comments.gmane.org/gmane.comp.sysutils.puppet.user/20597

But I wonder if there is a more modern way of doing it with 2.7.19 (or 3.0)?

Many thanks,
Eugene

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

Search Discussions

  • Peter Bukowinski at Oct 31, 2012 at 1:34 pm

    On Oct 31, 2012, at 8:52 AM, Eugene Vilensky wrote:

    Hello,

    I'm trying to send parameters to an Exec ("exec1") based on values, using a case statement. I've tried putting the two versions of the exec in a case block, which failed (exec1 is a dependency of exec2, and exec2 complained it could not find exec1), and a case statement can't go directly directly into the parameters of the Exec itself

    Google helped me with this thread: http://comments.gmane.org/gmane.comp.sysutils.puppet.user/20597

    But I wonder if there is a more modern way of doing it with 2.7.19 (or 3.0)?

    Many thanks,
    Eugene
    You may find the following example useful. It's a syslog class I use that uses case statements to set values for variables that are different depending on the operating system:

    class syslog {
    case $operatingsystem {
    'Fedora': {
    $servicename = 'rsyslog'
    $config = '/etc/rsyslog.conf'
    }
    'RedHat','Scientific': {
    case $operatingsystemrelease {
    /^6.*/: {
    $servicename = 'rsyslog'
    $config = '/etc/rsyslog.conf'
    }
    default: {
    $servicename = 'syslog'
    $config = '/etc/syslog.conf'
    }
    }
    }
    }
    service { $servicename:
    ensure => running,
    enable => true,
    hasrestart => true,
    hasstatus => true,
    }
    exec { "echo '*.*;local4.none @rsyslog' >> ${config}":
    unless => "grep -e '^\*\.\*;local4.none.*rsyslog$' ${config}",
    notify => Service[$servicename],
    }
    file { '/tmp/.syslog_restarted':
    ensure => file,
    content => '.',
    notify => Service[$servicename],
    }
    }

    If this doesn't help, can paste your code here so we give more specific feedback?

    --
    Peter Bukowinski


    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Jcbollinger at Nov 2, 2012 at 4:28 pm

    On Wednesday, October 31, 2012 7:53:21 AM UTC-5, Trammael wrote:
    Hello,

    I'm trying to send parameters to an Exec ("exec1") based on values, using
    a case statement. I've tried putting the two versions of the exec in a
    case block, which failed (exec1 is a dependency of exec2, and exec2
    complained it could not find exec1)

    That sounds like a different problem. If some other resource depends on
    Exec['exec1'], then you must ensure that it is declared. That declaration
    can certainly be in a case statement, but then you do need to ensure that
    every case declares a version of the Exec.


    , and a case statement can't go directly directly into the parameters of
    the Exec itself

    No, that's what selectors are for:

    exec { 'exec1':
    command => $color ? {
    blue => '/sbin/aix-foo',
    silver => '/sbin/osx_foo',
    red => '/sbin/rhel_foo',
    default => '/sbin/foo'
    }
    }


    Alternatively, you can assign the parameters to variables inside your case
    statement, then set the resource parameters via the variable values.

    Google helped me with this thread:
    http://comments.gmane.org/gmane.comp.sysutils.puppet.user/20597

    But I wonder if there is a more modern way of doing it with 2.7.19 (or
    3.0)?
    There is also the alternative of loading the wanted data from an external
    data source. That's not more "modern", really, as Puppet has had external
    data facilities for a long time. The community has, however, coalesced
    around "Hiera" for accessing external data. That was available as far back
    as Puppet 2.6, I believe, but it was a third-party add-on until its
    integration into the core in Puppet 3.


    John

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/vo5Skcm42moJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedOct 31, '12 at 12:53p
activeNov 2, '12 at 4:28p
posts3
users3
websitepuppetlabs.com

People

Translate

site design / logo © 2022 Grokbase