On 10/08/2011 12:28 AM, maillists0@gmail.com wrote:> New to puppet and I just don''t understand how to do this.
Apologies in
> advance if it''s a dumb question.
>
> Let''s say I have a module called httpd and inside that is a class
> called httpd::service, which accepts a couple of parameters:
>
> class httpd::service (
> $running = ''running'',
> $enabled = ''true'',
> ) {
> service { "httpd":
> path => "/etc/init.d/httpd",
> ensure => $running,
> enable => $enabled,
> require => [ Package[ "httpd" ], File[
"/etc/httpd/conf/httpd.conf" ] ],
> subscribe => File[ "/etc/httpd/conf/httpd.conf" ],
> }
> }
>
> But let''s say that I want to allow the option of both requiring
and
> subscribing to a second file -- any file -- in addition to httpd.conf.
> If I were doing this in a procedural language, I''d probably do
> something naive and create a couple of empty parameters called
> $also_subscribed and $myfile_path, use a conditional to see if
it''s
> defined, then create the arguments to require and subscribe based on
> that.
>
> I cannot figure out how to get this done in puppet. Any help is
> appreciated, even a link to an appropriate doc or example. Thanks!
I would use definition instead of class and it would look similar to this:
define httpd::service (
running = ''running'',
enabled = ''true'',
path = ''/etc/init.d/httpd'',
require = [ Package[ "httpd" ], File[
"/etc/httpd/conf/httpd.conf" ] ],
subscribe = File[ "/etc/httpd/conf/httpd.conf" ],
) {
service { "httpd":
path => $path,
ensure => $running,
enable => $enabled,
require => $require,
subscribe => $subscribe,
}
}
Now you''re able to override default values in this way:
httpd::service { path => ''/some/path'', }
You can also use assign array here:
$array = [ ''/some/path'', ''/another/path'' ]
httpd::service { path => $array, }
--
Dominik Zyla
--
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.