On Mon, Feb 6, 2012 at 2: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 > } > > -- > 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. > > Hey Greg, The include() function cannot take parameters, so you can't pass parameters this way. In order to declare a class WITH parameters, you'll need to pick one of a couple of ways: 1. Default the parameters to hiera lookups: Say you have a class like this: class sudo ( $webapp = $sudo::params::webapp ) { <puppet code> } In your params class you would do something like this: class sudo::params { $webapp = hiera('webapp', 'default value here') } All of the params would be defaulted to a value that came out of Hiera. In this case, there would be a Hiera lookup for a parameter called 'webapp' and, if it didn't find it, it would use the default value of 'default value here'. You could just do a hiera_include('classes') given that you have something like this in your Hiera YAML lookup: --- classes: - sudo # Note that this is the way to specify an array in YAML. Your array could be all of the class declarations you would want to make. No parameters would need be passed - they would be defaulted to a hiera lookup. You would need to make sure there are values for all your hiera parameter lookups, though. 2. Pass the class declaration, parameters and all, using create_resources() We have a function called create_resources() that's built into 2.7 but can be added to 2.6 with the following module: https://github.com/puppetlabs/puppetlabs-create_resources You could do something like this in your Hiera yaml files: --- param_classes: sudo: webapp : 'value' param : 'value' In your site.pp you would do something like this: $param_classes = hiera_hash('param_classes') create_resources('class', $param_classes) This would declare ALL class declarations found in the param_classes lookup done by Hiera. Hope this helps! -- Gary Larizza Professional Services Engineer Puppet Labs -- 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.