]> git.openstreetmap.org Git - chef.git/commitdiff
Compare kernel versions correctly
authorTom Hughes <tom@compton.nu>
Thu, 24 Jul 2014 11:31:07 +0000 (12:31 +0100)
committerTom Hughes <tom@compton.nu>
Thu, 24 Jul 2014 11:59:46 +0000 (12:59 +0100)
cookbooks/chef/libraries/compare_versions.rb [new file with mode: 0644]
cookbooks/devices/templates/default/udev.rules.erb

diff --git a/cookbooks/chef/libraries/compare_versions.rb b/cookbooks/chef/libraries/compare_versions.rb
new file mode 100644 (file)
index 0000000..d2ccf8a
--- /dev/null
@@ -0,0 +1,15 @@
+class Chef
+  class Util
+    def self.compare_versions(a, b)
+      if a.kind_of?(String)
+        a = a.split(".").map { |c| c.to_i }
+      end
+
+      if b.kind_of?(String)
+        b = b.split(".").map { |c| c.to_i }
+      end
+
+      a <=> b
+    end
+  end
+end
index 6a85600261fe1df81a4cfe1981cdb45b9ca21dcf..26fcec1da2761281f95eb3d63de84390367c4ef9 100644 (file)
@@ -24,7 +24,7 @@ ACTION=="add", SUBSYSTEM=="block", ENV{ID_BUS}=="<%= device[:bus] %>", ENV{ID_SE
 <% end -%>
 <% end -%>
 <% end -%>
-<% if node[:lsb][:release] == "12.04" && node[:kernel][:release].to_f >= 3.11 -%>
+<% if node[:lsb][:release] == "12.04" && Chef::Util.compare_versions(node[:kernel][:release], [3, 11]) >= 0 -%>
 
 # Rule from 14.04 udev for 12.04 machines running newer kernels
 ACTION=="add", SUBSYSTEM=="cpu", ENV{MODALIAS}=="?*", RUN+="/sbin/modprobe -bv $env{MODALIAS}"