Blank, Jessica
2007-Nov-07 17:00 UTC
A more elegant way of obtaining the major OS release number
Hello all:> We operate in an environment where we might sometimes wish to do > certain tasks based solely upon the MAJOR version number of an OS > release, disregarding the minor portion of the version number. For > instance, CentOS 4.0 through 4.5 would all be ''CentOS 4'' to some > scripts, and CentOS 5.0 and greater would all be ''CentOS 5''. > > I slightly modified facter (via editing > /usr/lib/site_ruby/1.8/facter.rb) to expose a new variable named > lsbdistrelease_majorversion which only includes the portion of the LSB > distribution release before the decimal point (if there is a point at > all): > > =======> 621c621,622 > < { "LSBRelease" => %r{^LSB Version:\t(.*)$}, > --- > > { > > "LSBRelease" => %r{^LSB Version:\t(.*)$}, > 623a625 > > "LSBDistRelease_MajorVersion" => > %r{^Release:\t([0-9]+)}, > ======> > However, this seems like a rather unelegant, non-standard solution, > and it''s Linux-specific! > > Can you think of any way in which one might distinguish between, say, > ''Solaris 7'' and ''Solaris 8'', without caring if it''s 7.1 or 7.2 or 7.3 > within ''7''... or ''CentOS 4'' without distinguishing between 4.0 or 4.5? > > Any feedback you could provide along these lines would be very much > appreciated. I can''t seem to find a way to do something like: > > ==============================> class osdep-helloworld { > file { "/etc/helloworld": > owner => root, > group => root, > mode => 443, > source => $lsbdistrelease ? { > >=4 => > "puppet://puppetmaster.1515.mtvi.com/dist/apps/misc/helloworld-centos- > 4", > >=5 => > "puppet://puppetmaster.1515.mtvi.com/dist/apps/misc/helloworld-centos- > 5", > } > } > } > ==============================> > Instead, I''d have to do a kluge like this: > > > ==============================> class osdep-helloworld { > file { "/etc/helloworld": > owner => root, > group => root, > mode => 456, > source => $lsbdistrelease ? { > "4.0" => > "puppet://puppetmaster.1515.mtvi.com/dist/apps/misc/helloworld-centos- > 4", > "4.1" => > "puppet://puppetmaster.1515.mtvi.com/dist/apps/misc/helloworld-centos- > 4", > "4.2" => > "puppet://puppetmaster.1515.mtvi.com/dist/apps/misc/helloworld-centos- > 4", > "4.3" => > "puppet://puppetmaster.1515.mtvi.com/dist/apps/misc/helloworld-centos- > 4", > "4.4" => > "puppet://puppetmaster.1515.mtvi.com/dist/apps/misc/helloworld-centos- > 4", > "4.5" => > "puppet://puppetmaster.1515.mtvi.com/dist/apps/misc/helloworld-centos- > 4", > "5" => > "puppet://puppetmaster.1515.mtvi.com/dist/apps/misc/helloworld-centos- > 5", > } > } > } > ==============================> > Or, of course, use my modification to facter. > > I eagerly await any helpful hints you might be able to offer. > > Many thanks, > > --Jessica_______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
David Schmitt
2007-Nov-07 20:17 UTC
Re: A more elegant way of obtaining the major OS release number
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wednesday 07 November 2007, Blank, Jessica wrote:> Hello all: > > We operate in an environment where we might sometimes wish to do > > certain tasks based solely upon the MAJOR version number of an OS > > release, disregarding the minor portion of the version number. For > > instance, CentOS 4.0 through 4.5 would all be ''CentOS 4'' to some > > scripts, and CentOS 5.0 and greater would all be ''CentOS 5''. > >> > I eagerly await any helpful hints you might be able to offer.You could write yourself a function which munges the value as needed. See the wiki on "WritingYourOwnFunctions" or the functions in my repo at http://git.black.co.at/?p=manifests.git;a=tree;f=modules/common/plugins/puppet/parser/functions;hb=HEAD . Especially the gsub function might be of use to you. Regards, David - -- The primary freedom of open source is not the freedom from cost, but the free- dom to shape software to do what you want. This freedom is /never/ exercised without cost, but is available /at all/ only by accepting the very different costs associated with open source, costs not in money, but in time and effort. - -- http://www.schierer.org/~luke/log/20070710-1129/on-forks-and-forking -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFHMh1N/Pp1N6Uzh0URAtN1AJ9+DXineqkL/1iz+TTa7X4h6VP8LACgnKIU 0RM1Dfle6jRlt3X+a4ogyvc=9MqD -----END PGP SIGNATURE-----