summaryrefslogtreecommitdiff
path: root/lib/facter/python_version.rb
blob: bb9ec9806160e6a0e2acdb3187115ad395e9cd9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Make python versions available as facts
# In lists default python and system python versions
require 'puppet'
pkg = Puppet::Type.type(:package).new(:name => "python")

Facter.add("system_python_version") do
  setcode do
    begin
      unless [:absent,'purged'].include?(pkg.retrieve[pkg.property(:ensure)])
          /^(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1]
      end
    rescue
      false
    end
  end
end

Facter.add("python_version") do
  has_weight 100
  setcode do
    begin
      /^.*(\d+\.\d+\.\d+)$/.match(Facter::Util::Resolution.exec('python -V 2>&1'))[1]
    rescue
      false
    end
  end
end

Facter.add("python_version") do
  has_weight 50
  setcode do
    begin
      unless [:absent,'purged'].include?(pkg.retrieve[pkg.property(:ensure)])
          /^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1]
      end
    rescue
      false
    end
  end
end