Elias,

cat '/etc/redhat-release |awk {'print $3'}|cut -c1' works fine under
redhat and centos, however I just tested it and it's worth noting that
it doesn't work under scientific linux.

Gary,

Using the facter value is great, thanks. I didn't think of doing this.
It's by far the neatest and most elegant way to do this. Always good
to push the heavy lifting upstream. :)

On Feb 12, 6:25 pm, Gary Larizza <g...@puppetlabs.com> wrote:
> There's also the 'operatingsystemrelease' fact that will evaluate to the
> full version.  You could do this:
>
> Facter.add('operatingsystemmajor') do
>   setcode do
>     Facter.value('operatingsystemrelease').split('.').first
>   end
> end
>
> If you do choose to use the shell command, you can do this:
>
> Facter.add('operatingsystemmajor') do
>   setcode("cat /etc/redhat-release | awk \{'print $3'\}|cut - c1")
> end
>
> Passing a string to the setcode method in Facter will automatically pipe
> the command to Facter::Util::Resolution.exec which will execute the command
> and return the value from stdout.  Using Facter::Util::Resolution.exec() is
> better than %x{} because it has a built-in timeout (so if your command
> hangs your facter/puppet run won't).  It also handles nil values well, has
> a built-in PATH environment variable, and handles invalid commands a bit
> better than %x{}  (plus, just passing an argument to setcode is a bit
> cleaner).
>
> On Sun, Feb 12, 2012 at 2:12 PM, Elias Abacioglu <elias.r...@gmail.com>wrote:
>
>
>
>
>
>
>
>
>
> > On 8 February 2012 02:37, 
> > d...@looprock.com<technopatholo*...@gmail.com<technopathol...@gmail.com>>
> >>  wrote:
> >> I use this:
>
> >> Facter.add("**operatingsystemrelease_mv") do
> >>        setcode do
> >>                %x{cat /etc/redhat-release |awk \{'print $3'\}|cut -
> >> c1}.chomp
> >>        end
> >> end
>
> > I think that will fail on centos. This line is better, works on
> > centos/rhel.
>
> > cat /etc/redhat-release |awk -Frelease {'print $2'}  | awk {'print $1'} |
> > awk -F. {'print $1'}
>
> > --
> > 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 <puppet-users%2bunsubscr...@googlegroups.com>.
> > For more options, visit this group athttp://groups.google.com/**
> > group/puppet-users?hl=en<http://groups.google.com/group/puppet-users?hl=en>
> > .
>
> --
>
> 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.

Reply via email to