Discussion:
[Puppet Users] case statement exec
Eugene Vilensky
2012-10-31 12:52:54 UTC
Permalink
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-***@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Peter Bukowinski
2012-10-31 13:08:33 UTC
Permalink
Post by Eugene Vilensky
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-***@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2012-11-02 16:28:10 UTC
Permalink
Post by Eugene Vilensky
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.
Post by Eugene Vilensky
, 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.
Post by Eugene Vilensky
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-***@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Continue reading on narkive:
Loading...