c10ad2a29ab087207734a8c90e8fa3fdc51c374a
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / lib / facter / postgres_default_version.rb
1 def get_debianfamily_postgres_version
2   case Facter.value('operatingsystem')
3     when "Debian"
4       get_debian_postgres_version()
5     when "Ubuntu"
6       get_ubuntu_postgres_version()
7     else
8       nil
9   end
10 end
11
12 def get_debian_postgres_version
13   case Facter.value('operatingsystemrelease')
14     # TODO: add more debian versions or better logic here
15     when /^6\./
16       "8.4"
17     when /^wheezy/, /^7\./
18       "9.1"
19     else
20       nil
21   end
22 end
23
24 def get_ubuntu_postgres_version
25   case Facter.value('operatingsystemrelease')
26     when "11.10", "12.04", "12.10", "13.04"
27       "9.1"
28     when "10.04", "10.10", "11.04"
29       "8.4"
30     else
31       nil
32   end
33 end
34
35 def get_redhatfamily_postgres_version
36   case Facter.value('operatingsystemrelease')
37     when /^6\./
38       "8.4"
39     when /^5\./
40       "8.1"
41     else
42       nil
43   end
44 end
45
46 Facter.add("postgres_default_version") do
47   setcode do
48     result =
49       case Facter.value('osfamily')
50         when 'RedHat'
51           get_redhatfamily_postgres_version()
52         when 'Linux'
53           get_redhatfamily_postgres_version()
54         when 'Debian'
55           get_debianfamily_postgres_version()
56         else
57           nil
58       end
59
60     # TODO: not sure if this is really a great idea, but elsewhere in the code
61     # it is useful to be able to distinguish between the case where the fact
62     # does not exist at all (e.g., if pluginsync is not enabled), and the case
63     # where the fact is not known for the OS in question.
64     if result == nil
65       result = 'unknown'
66     end
67     result
68   end
69 end