Class: ChefApply::Action::InstallChef::MinimumChefVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/chef_apply/action/install_chef/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"),
  },
  macos: {
    13 => Gem::Version.new("13.10.4"),
    14 => Gem::Version.new("14.1.1"),
  },
  solaris: {
      13 => Gem::Version.new("13.10.4"),
      14 => Gem::Version.new("14.1.1"),
  },
  aix: {
      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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/chef_apply/action/install_chef/minimum_chef_version.rb', line 50

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