From d007a403330c553d925b1b4888d93962a5f83f99 Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Mon, 11 May 2015 10:49:27 -0400 Subject: Replace debian_*() parser functions with facts * Removes dependency on lsb-release and/or Facter >1.7 (values are based on $::lsbdistcodename, when available) * Simplifies maintenance: only lib/facter/util/* require updates as new releases are made Caveats: * apt::codename is removed; to override debian_* facts, set the FACTER_debian_codename environment variable for puppet * If tracking unstable, make sure lsb-release is installed, as other methods can't tell between testing and unstable --- lib/facter/debian_codename.rb | 40 +++++++++++++++++++++++++++++++++++++++ lib/facter/debian_lts.rb | 14 ++++++++++++++ lib/facter/debian_nextcodename.rb | 22 +++++++++++++++++++++ lib/facter/debian_nextrelease.rb | 23 ++++++++++++++++++++++ lib/facter/debian_release.rb | 36 +++++++++++++++++++++++++++++++++++ lib/facter/ubuntu_codename.rb | 8 ++++++++ lib/facter/ubuntu_nextcodename.rb | 18 ++++++++++++++++++ lib/facter/util/debian.rb | 18 ++++++++++++++++++ lib/facter/util/ubuntu.rb | 20 ++++++++++++++++++++ 9 files changed, 199 insertions(+) create mode 100644 lib/facter/debian_codename.rb create mode 100644 lib/facter/debian_lts.rb create mode 100644 lib/facter/debian_nextcodename.rb create mode 100644 lib/facter/debian_nextrelease.rb create mode 100644 lib/facter/debian_release.rb create mode 100644 lib/facter/ubuntu_codename.rb create mode 100644 lib/facter/ubuntu_nextcodename.rb create mode 100644 lib/facter/util/debian.rb create mode 100644 lib/facter/util/ubuntu.rb (limited to 'lib/facter') diff --git a/lib/facter/debian_codename.rb b/lib/facter/debian_codename.rb new file mode 100644 index 0000000..73eeea2 --- /dev/null +++ b/lib/facter/debian_codename.rb @@ -0,0 +1,40 @@ +begin + require 'facter/util/debian' +end + +def version_to_codename(version) + if Facter::Util::Debian::CODENAMES.has_key?(version) + return Facter::Util::Debian::CODENAMES[version] + else + Facter.warn("Could not determine codename from version '#{version}'") + end +end + +Facter.add(:debian_codename) do + has_weight 99 + confine :operatingsystem => 'Debian' + setcode do + Facter.value('lsbdistcodename') + end +end + +Facter.add(:debian_codename) do + has_weight 66 + confine :operatingsystem => 'Debian' + setcode do + version_to_codename(Facter.value('operatingsystemmajrelease')) + end +end + +Facter.add(:debian_codename) do + has_weight 33 + confine :operatingsystem => 'Debian' + setcode do + debian_version = File.open('/etc/debian_version', &:readline) + if debian_version.match(/^\d+/) + version_to_codename(version_to_codename.scan(/^(\d+)/)[0][0]) + elsif debian_version.match(/^[a-z]+\/(sid|unstable)/) + debian_version.scan(/^([a-z]+)\//)[0][0] + end + end +end diff --git a/lib/facter/debian_lts.rb b/lib/facter/debian_lts.rb new file mode 100644 index 0000000..1c137e1 --- /dev/null +++ b/lib/facter/debian_lts.rb @@ -0,0 +1,14 @@ +begin + require 'facter/util/debian' +end + +Facter.add(:debian_lts) do + confine :operatingsystem => 'Debian' + setcode do + if Facter::Util::Debian::LTS.include? Facter.value('debian_codename') + true + else + false + end + end +end diff --git a/lib/facter/debian_nextcodename.rb b/lib/facter/debian_nextcodename.rb new file mode 100644 index 0000000..755a0e5 --- /dev/null +++ b/lib/facter/debian_nextcodename.rb @@ -0,0 +1,22 @@ +begin + require 'facter/util/debian' +end + +def debian_codename_to_next(codename) + if codename == "sid" + return "experimental" + else + codenames = Facter::Util::Debian::CODENAMES.values.reverse + i = codenames.index(codename) + if i and i+1 < codenames.count + return codenames[i+1] + end + end +end + +Facter.add(:debian_nextcodename) do + confine :operatingsystem => 'Debian' + setcode do + debian_codename_to_next(Facter.value('debian_codename')) + end +end diff --git a/lib/facter/debian_nextrelease.rb b/lib/facter/debian_nextrelease.rb new file mode 100644 index 0000000..2a9c4f5 --- /dev/null +++ b/lib/facter/debian_nextrelease.rb @@ -0,0 +1,23 @@ +def debian_release_to_next(release) + releases = [ + 'oldoldoldstable', + 'oldoldstable', + 'oldstable', + 'stable', + 'testing', + 'unstable', + 'experimental', + ] + if releases.include? release + if releases.index(release)+1 < releases.count + return releases[releases.index(release)+1] + end + end +end + +Facter.add(:debian_nextrelease) do + confine :operatingsystem => 'Debian' + setcode do + debian_release_to_next(Facter.value('debian_release')) + end +end diff --git a/lib/facter/debian_release.rb b/lib/facter/debian_release.rb new file mode 100644 index 0000000..09e8eef --- /dev/null +++ b/lib/facter/debian_release.rb @@ -0,0 +1,36 @@ +begin + require 'facter/util/debian' +end + +def debian_codename_to_release(codename) + stable = Facter::Util::Debian::STABLE + versions = Facter::Util::Debian::CODENAMES.invert + release = nil + if codename == "sid" + release = "unstable" + elsif versions.has_key? codename + version = versions[codename].to_i + if version == stable + release = "stable" + elsif version < stable + release = "stable" + for i in version..stable - 1 + release = "old" + release + end + elsif version == stable + 1 + release = "testing" + end + end + if release.nil? + Facter.warn("Could not determine release from codename #{codename}!") + end + return release +end + +Facter.add(:debian_release) do + has_weight 99 + confine :operatingsystem => 'Debian' + setcode do + debian_codename_to_release(Facter.value('debian_codename')) + end +end diff --git a/lib/facter/ubuntu_codename.rb b/lib/facter/ubuntu_codename.rb new file mode 100644 index 0000000..814fd94 --- /dev/null +++ b/lib/facter/ubuntu_codename.rb @@ -0,0 +1,8 @@ +Facter.add(:ubuntu_codename) do + confine :operatingsystem => 'Ubuntu' + setcode do + Facter.value('lsbdistcodename') + end +end + + diff --git a/lib/facter/ubuntu_nextcodename.rb b/lib/facter/ubuntu_nextcodename.rb new file mode 100644 index 0000000..38b64ad --- /dev/null +++ b/lib/facter/ubuntu_nextcodename.rb @@ -0,0 +1,18 @@ +begin + require 'facter/util/ubuntu' +end + +def ubuntu_codename_to_next(codename) + codenames = Facter::Util::Ubuntu::CODENAMES + i = codenames.index(codename) + if i and i+1 < codenames.count + return codenames[i+1] + end +end + +Facter.add(:ubuntu_nextcodename) do + confine :operatingsystem => 'Ubuntu' + setcode do + ubuntu_codename_to_next(Facter.value('ubuntu_codename')) + end +end diff --git a/lib/facter/util/debian.rb b/lib/facter/util/debian.rb new file mode 100644 index 0000000..290c17b --- /dev/null +++ b/lib/facter/util/debian.rb @@ -0,0 +1,18 @@ +module Facter + module Util + module Debian + STABLE = 8 + CODENAMES = { + "5" => "lenny", + "6" => "squeeze", + "7" => "wheezy", + "8" => "jessie", + "9" => "stretch", + "10" => "buster", + } + LTS = [ + "squeeze", + ] + end + end +end diff --git a/lib/facter/util/ubuntu.rb b/lib/facter/util/ubuntu.rb new file mode 100644 index 0000000..1b2411a --- /dev/null +++ b/lib/facter/util/ubuntu.rb @@ -0,0 +1,20 @@ +module Facter + module Util + module Ubuntu + CODENAMES = [ + "lucid", + "maverick", + "natty", + "oneiric", + "precise", + "quantal", + "raring", + "saucy", + "trusty", + "utopic", + "vivid", + "wily", + ] + end + end +end -- cgit v1.2.3 From 3a7dd605e344cd8bdfa33a1fb82bfefe948cbd00 Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Wed, 3 Jun 2015 16:20:36 -0400 Subject: Fix bug with debian_nextcodename --- lib/facter/debian_nextcodename.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/facter') diff --git a/lib/facter/debian_nextcodename.rb b/lib/facter/debian_nextcodename.rb index 755a0e5..af16cc8 100644 --- a/lib/facter/debian_nextcodename.rb +++ b/lib/facter/debian_nextcodename.rb @@ -6,7 +6,7 @@ def debian_codename_to_next(codename) if codename == "sid" return "experimental" else - codenames = Facter::Util::Debian::CODENAMES.values.reverse + codenames = Facter::Util::Debian::CODENAMES.values i = codenames.index(codename) if i and i+1 < codenames.count return codenames[i+1] -- cgit v1.2.3 From 3dea5b8df77f1ab8224037eacb186ff0c026e378 Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Fri, 9 Oct 2015 17:12:31 -0400 Subject: Fix debian_codename fact when falling back to parsing /etc/debian_version --- lib/facter/debian_codename.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/facter') diff --git a/lib/facter/debian_codename.rb b/lib/facter/debian_codename.rb index 73eeea2..06ec5ff 100644 --- a/lib/facter/debian_codename.rb +++ b/lib/facter/debian_codename.rb @@ -32,7 +32,7 @@ Facter.add(:debian_codename) do setcode do debian_version = File.open('/etc/debian_version', &:readline) if debian_version.match(/^\d+/) - version_to_codename(version_to_codename.scan(/^(\d+)/)[0][0]) + version_to_codename(debian_version.scan(/^(\d+)/)[0][0]) elsif debian_version.match(/^[a-z]+\/(sid|unstable)/) debian_version.scan(/^([a-z]+)\//)[0][0] end -- cgit v1.2.3 From a70c52c1d4f399c22fa6c71289031350a1da44b5 Mon Sep 17 00:00:00 2001 From: varac Date: Mon, 7 Dec 2015 14:27:04 +0100 Subject: Fix loading of util/debian.rb for custom facts requirering the facter/util/debian.rb module causes puppet warnings on wheezy hosts, and custom facts like `$::debian_codename` cannot be evaluated. warning: Could not load fact file /srv/dev/projects/puppet/shared-modules//apt/lib/facter/debian_nextcodename.rb: no such file to load -- facter/util/debian Removing the require line solves this. --- lib/facter/debian_codename.rb | 2 ++ lib/facter/debian_lts.rb | 2 ++ lib/facter/debian_nextcodename.rb | 2 ++ lib/facter/debian_release.rb | 2 ++ lib/facter/ubuntu_nextcodename.rb | 2 ++ 5 files changed, 10 insertions(+) (limited to 'lib/facter') diff --git a/lib/facter/debian_codename.rb b/lib/facter/debian_codename.rb index 06ec5ff..254877a 100644 --- a/lib/facter/debian_codename.rb +++ b/lib/facter/debian_codename.rb @@ -1,5 +1,7 @@ begin require 'facter/util/debian' +rescue LoadError + require "#{File.dirname(__FILE__)}/util/debian" end def version_to_codename(version) diff --git a/lib/facter/debian_lts.rb b/lib/facter/debian_lts.rb index 1c137e1..f53a9eb 100644 --- a/lib/facter/debian_lts.rb +++ b/lib/facter/debian_lts.rb @@ -1,5 +1,7 @@ begin require 'facter/util/debian' +rescue LoadError + require "#{File.dirname(__FILE__)}/util/debian" end Facter.add(:debian_lts) do diff --git a/lib/facter/debian_nextcodename.rb b/lib/facter/debian_nextcodename.rb index af16cc8..6e994a4 100644 --- a/lib/facter/debian_nextcodename.rb +++ b/lib/facter/debian_nextcodename.rb @@ -1,5 +1,7 @@ begin require 'facter/util/debian' +rescue LoadError + require "#{File.dirname(__FILE__)}/util/debian" end def debian_codename_to_next(codename) diff --git a/lib/facter/debian_release.rb b/lib/facter/debian_release.rb index 09e8eef..2c334cc 100644 --- a/lib/facter/debian_release.rb +++ b/lib/facter/debian_release.rb @@ -1,5 +1,7 @@ begin require 'facter/util/debian' +rescue LoadError + require "#{File.dirname(__FILE__)}/util/debian" end def debian_codename_to_release(codename) diff --git a/lib/facter/ubuntu_nextcodename.rb b/lib/facter/ubuntu_nextcodename.rb index 38b64ad..ba985bf 100644 --- a/lib/facter/ubuntu_nextcodename.rb +++ b/lib/facter/ubuntu_nextcodename.rb @@ -1,5 +1,7 @@ begin require 'facter/util/ubuntu' +rescue LoadError + require "#{File.dirname(__FILE__)}/util/debian" end def ubuntu_codename_to_next(codename) -- cgit v1.2.3 From 5381cb7b617a78b75b593a21fe9e0e8356013f6a Mon Sep 17 00:00:00 2001 From: varac Date: Mon, 7 Dec 2015 16:51:20 +0100 Subject: [bug] Fix debian_nextcodename on wheezy hosts I noticed this behaviour because $::debian_nextcodename was "squeeze" on a wheezy host. For debugging, i inserted a "puts codenames" in lib/facter/debian_nextcodename.rb, and it turned out that it was sorted differently on wheezy and jessie hosts: On wheezy: buster stretch jessie wheezy squeeze lenny On jessie: lenny squeeze wheezy jessie stretch buster So i decided to rewrite this so this doesn't happen again. --- lib/facter/debian_nextcodename.rb | 9 ++++----- lib/facter/util/ubuntu.rb | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/facter') diff --git a/lib/facter/debian_nextcodename.rb b/lib/facter/debian_nextcodename.rb index 6e994a4..c4c569b 100644 --- a/lib/facter/debian_nextcodename.rb +++ b/lib/facter/debian_nextcodename.rb @@ -8,11 +8,10 @@ def debian_codename_to_next(codename) if codename == "sid" return "experimental" else - codenames = Facter::Util::Debian::CODENAMES.values - i = codenames.index(codename) - if i and i+1 < codenames.count - return codenames[i+1] - end + codenames = Facter::Util::Debian::CODENAMES + versions = Facter::Util::Debian::CODENAMES.invert + current_version = versions[codename] + return codenames[(current_version.to_i + 1).to_s] end end diff --git a/lib/facter/util/ubuntu.rb b/lib/facter/util/ubuntu.rb index 1b2411a..52c15e8 100644 --- a/lib/facter/util/ubuntu.rb +++ b/lib/facter/util/ubuntu.rb @@ -14,6 +14,7 @@ module Facter "utopic", "vivid", "wily", + "xenial" ] end end -- cgit v1.2.3 From abe5212b01a9ed889a486795b26e845f56e334a2 Mon Sep 17 00:00:00 2001 From: varac Date: Mon, 7 Dec 2015 21:55:01 +0100 Subject: Fix require path for ubuntu_nextcodename.rb --- lib/facter/ubuntu_nextcodename.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/facter') diff --git a/lib/facter/ubuntu_nextcodename.rb b/lib/facter/ubuntu_nextcodename.rb index ba985bf..dcd1d42 100644 --- a/lib/facter/ubuntu_nextcodename.rb +++ b/lib/facter/ubuntu_nextcodename.rb @@ -1,7 +1,7 @@ begin require 'facter/util/ubuntu' rescue LoadError - require "#{File.dirname(__FILE__)}/util/debian" + require "#{File.dirname(__FILE__)}/util/ubuntu" end def ubuntu_codename_to_next(codename) -- cgit v1.2.3