Class: ChefApply::MinimumChefVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/chef_apply/minimum_chef_version.rb

Defined Under Namespace

Classes: Client13Outdated, Client14Outdated, ClientNotInstalled

Constant Summary collapse

CONSTRAINTS =
{
  windows: {
    13 => Gem::Version.new("13.10.4"),
    14 => Gem::Version.new("14.4.22"),
  },
  linux: {
    13 => Gem::Version.new("13.10.4"),
    14 => Gem::Version.new("14.1.1"),
  },
}.freeze

Class Method Summary collapse

Class Method Details

.check!(target, check_only) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/chef_apply/minimum_chef_version.rb', line 34

def self.check!(target, check_only)
  begin
    installed_version = target.installed_chef_version
  rescue ChefApply::TargetHost::ChefNotInstalled
    if check_only
      raise ClientNotInstalled.new()
    end
    return :client_not_installed
  end

  os_constraints = CONSTRAINTS[target.base_os]
  min_14_version = os_constraints[14]
  min_13_version = os_constraints[13]

  case
    when installed_version >= Gem::Version.new("14.0.0") && installed_version < min_14_version
      raise Client14Outdated.new(installed_version, min_14_version)
    when installed_version >= Gem::Version.new("13.0.0") && installed_version < min_13_version
      raise Client13Outdated.new(installed_version, min_13_version, min_14_version)
    when installed_version < Gem::Version.new("13.0.0")
      # If they have Chef < 13.0.0 installed we want to show them the easiest upgrade path -
      # Chef 13 first and then Chef 14 since most customers cannot make the leap directly
      # to 14.
      raise Client13Outdated.new(installed_version, min_13_version, min_14_version)
  end

  :minimum_version_met
end