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 <[email protected]>wrote:

> On 8 February 2012 02:37, 
> [email protected]<technopatholo**[email protected]<[email protected]>>
>>  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 [email protected].
> To unsubscribe from this group, send email to puppet-users+unsubscribe@**
> googlegroups.com <puppet-users%[email protected]>.
> For more options, visit this group at http://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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to