On Tue, Feb 7, 2012 at 6:19 AM, jcbollinger <john.bollin...@stjude.org> wrote:
>
>
> On Feb 6, 4:23 pm, Gmoney <greg.caldwe...@gmail.com> wrote:
>> I am using puppet 2.6.11 and want to pass parameter for implementing
>> sudo for mulitple users. So here is my simple code, which I would like
>> to pass to hiera to specify user name lookup. Appreciate any help,
>> thanks in advance.
>>
>> class sudo( $name) {
>> #Class:: sudo
>> #
>> #
>>
>> package { "sudo": ensure => present, }
>>
>> file { "/etc/sudoers":
>>     owner   => root,
>>     group   => root,
>>     mode    => 440,
>>     source  => "puppet:///modules/sudo/sudoers.$name",
>>   }
>>
>> }   # Class:: sudo
>>
>> Hiera FIle for node :
>>
>> hostname01.yaml
>> =============
>>
>> ---
>> config:  - XXXX
>> server:  - hostname01p
>> node_classes: - sudo('webapp')
>>
>> I get this error message when trying to apply on node:
>>
>> puppet agent -tv --noop
>> err: Could not retrieve catalog from remote server: Error 400 on
>> SERVER: Invalid tag "sudo('webapp')" at /etc/puppet/manifests/site.pp:
>> 19 on node
>>
>> cat /etc/puppet/manifests/site.pp ( portion of file )
>> ===================================
>>
>> node default {
>>
>>    hiera_include( "node_classes" )       # Maintained in hostgroups/
>> <hostgroup>/<site>/<hostname>.yaml
>>
>> }
>
>
> One of the strong points of using external data is the ability to
> *avoid* using parameterized classes, which is a Good Thing to do.
> External data solve all the same technical problems that class
> parameters do, without incurring the costs that attend parameterizing
> a class (such as the one you encountered).

I agree with some of the limitations of parametrized class that
doesn't support default value. But in this case I'd argue the
opposite. Using hiera allows the usage of parametrized class, gives a
clean interface to the class, allows the usage of include class, and
eliminates hideous variable validation and the necessity of real_param
(if you want to provide defaults within the puppet manifests and not
completely depend on external data lookup for default value).

For example:

class mysql {
...
  if !$password (
    fail('must have password')
  }
  if !$server {
    real_server = 'localhost',
  } else
    real_server = $server,
  }
...
}

class mysql(
  $password = hiera('mysql_password'),
  $server = hiera('mysql_server', 'localhost')
) {
...
}

Both examples above would work with include mysql, and I think the
second one is much cleaner. If you adapt hiera,  I recommend the using
parametrized class with all parameter values lookup performed via
hiera. Rather than shunning parametrized class, I think hiera gives
you a great way to leverage it without the downsides.

Thanks,

Nan

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to