Puppet: System Administration Automated

Support

Get the SuSE Version

Why? Still working with SuSE/SLES 8/9 and use different repositories for each, so I needed the local OS version to identify the needed repository.

Shiny new version.

# suse.rb
require 'facter'

if Facter.kernel == "Linux"

  arch = ''
  version = ''
  sles = false
  repo_name = nil

  if FileTest.exists?("/etc/SuSE-release")

    lines = File.readlines("/etc/SuSE-release")

    lines.each do |line|
      arch = $1 if line.match(/\((.*)\)/)
      version = $1 if line.match(/VERSION = ([\d+\.]+)/)
      sles = true unless line.grep(/Enterprise/).empty?
    end

    if sles
      repo_name = "sles#{version}-#{arch}"
      version = "sles#{version}"
    else
      repo_name = "suse#{version.delete('.')}"
    end

    # Returns SuSE version => "8.1"
    Facter.add("suse_version") do
      confine :kernel => :linux
      setcode do
        version
      end
    end

    # Returns SuSE arch => "i586"
    Facter.add("suse_arch") do
      confine :kernel => :linux
      setcode do
        arch
      end
    end

    # Returns SuSE reponame => "sles9-x86_64" or "suse80"
    Facter.add("suse_repo_name") do
      confine :kernel => :linux
      setcode do
        repo_name
      end
    end
  end

end

Old version. Note that this doesn´t return the patchlevel, just a plain "8" if its a SuSE 8.X and "9" if its a SuSE 9.X.

Facter.add("suse_version") do
        setcode do
                File.readlines("/etc/SuSE-release").to_s.match(/VERSION = (\d+)/).to_a.last
        end
end

Attachments