Well, I understand that much, but I want to validate that the parameter passed to the called class is valid.
Right now I'm doing the logic for setting the valid releases in the params class, like this: case $::osfamily { 'RedHat': { $available_releases = ['5.5', '10.0'] } 'Debian': { case $os { 'debian': { case $::lsbmajrelease { '6': { $available_releases = ['5.2', '5.3', '5.5', '10.0'] } '7': { $available_releases = ['5.5', '10.0'] } default: { fail( "MariaDB not supported on ${::operatingsystem} ${::operatingsystemrelease}" ) } } } 'ubuntu': { case $::lsbdistcodename { /(hardy|maverick|natty|oneiric)/: { if $::operatingsystem == 'LinuxMint' { fail( "MariaDB not supported on ${::operatingsystem} ${::operatingsystemrelease}" ) } else { $available_releases = ['5.2', '5.3'] } } 'lucid': { $available_releases = ['5.2', '5.3', '5.5', '10.0'] } /(precise|quantal|raring)/: { $available_releases = ['5.5', '10.0'] } default: { fail( "MariaDB not supported on ${::operatingsystem} ${::operatingsystemrelease}" ) } } } default: { fail( "MariaDB not supported on ${::operatingsystem} ${::operatingsystemrelease}" ) } } } And then I do the validation of the $version variable as such: if ! ($version in $available_releases) { warning( "MariaDB ${version} not supported on ${::operatingsystem} ${::operatingsystemrelease}, setting release to ${available_releases[-1]}" ) $version = $available_releases[-1] } But maybe I just need to set the default value in params, and do the validation in the maria class itself, to make sure scope is correct. Then I would have to simply fail puppet, and not try to correct the user error, like this: if ! ($version in $maria::params::available_releases) { fail( "MariaDB ${version} not supported on ${::operatingsystem} ${::operatingsystemrelease}, setting release to ${available_releases[-1]}" ) } On Tuesday, July 30, 2013 8:29:40 AM UTC-4, Rahul Khengare wrote: > > Hi Stephen, > As per my understanding of your query, you want version parameter value > 5.5 as default and on passing parameter value its become 5.3. > But in your case its take version = 5.5. Correct me if i am wrong. > > Solution for your query is u have to construct parameterized class maria > and it has to be inheriated by maria::params. > > # maria class > class maria ( > $version = maria::params::version > ) inherits maria::params { > > notify { "$version" :} > } > > # params class > class maria::params { > $version = '5.5' > } > > # when we call the class maria with version parameter it set the $version > value to passed value (here 5.3) > class {"maria": > $version => '5.3' > } > > # when we call the class maria without version parameter it set the > $version value to default value from params class (here 5.5) > class {"maria": > } > > I hope this will solve your problem. If i interpreted your query correctly. > > Thanks and Regards, > Rahul Khengare. > NTT DATA GTS (OSS centre) > pune > > > On Tuesday, July 30, 2013 12:08:17 AM UTC+5:30, Stephen Brown II wrote: >> >> Greetings all, >> >> I have a feeling I'm trying to be a bit too clever for my own good, or >> making the mistake of treating the declarative language as a procedural. >> But at any rate, here is my issue. >> >> I would like to set up a params class ( in the style of >> http://docs.puppetlabs.com/guides/parameterized_classes<http://docs.puppetlabs.com/guides/parameterized_classes.html#appendix-smart-parameter-defaults> >> ) for >> installing mariadb on any operating system that is supported by the >> official mariadb.org repository configuratior: >> https://downloads.mariadb.org/mariadb/repositories/ >> >> However, I've noticed that not all versions of MariaDB are available for >> all OS releases. For the most part, 5.5 and 10.0 are available, but for >> older versions of Ubuntu /(hardy|maverick|natty|oneiric)/, only 5.2 and 5.3 >> are available. >> >> Here is the gist of my params.pp as it stands: >> https://gist.github.com/StephenBrown2/6106113 >> >> What I would eventually like to get working is the ability for the module >> to set a reasonable default, and also allow for overriding in the calling, >> but if the operating system doesn't support that MariaDB release version, >> to use the latest available release instead. >> >> For example, this should work fine: >> >> class { 'maria': } >> >> This should also work: >> >> class { 'maria': >> version => '5.5', >> } >> >> both resulting in mariadb 5.5 being installed on anything but those older >> ubuntu's. in which case, Puppet would throw a warning and set $version >> instead to '5.3'. >> >> Similarly, if this was specified: >> >> class { 'maria': >> version => '5.3', >> } >> >> on a Debian 7 system, I'd expect it to come back as '10.0'. But this >> might be where the cleverness could be a liability. >> >> Might I have to simply set the default version for each possible >> operatingsystem value? I would hope not, as that seems a bit unweildy, but >> maybe necessary since variables can only be declared once per scope ( >> http://docs.puppetlabs.com/learning/variables<http://docs.puppetlabs.com/learning/variables.html#variables> >> : "You can only assign the same variable *once* in a given scope." ) >> >> Please let me know if I've been unclear, or enlighten me if this is going >> down the wrong path. >> >> Thanks! >> Stephen B >> > -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.