Class: OctocatalogDiff::Util::PuppetVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/octocatalog-diff/util/puppetversion.rb

Overview

This is a utility class to determine the version of Puppet.

Class Method Summary collapse

Class Method Details

.puppet_version(puppet, options = {}) ⇒ String

Determine the version of Puppet.

Parameters:

  • puppet (String)

    Path to Puppet binary

  • options (Hash) (defaults to: {})

    Options hash as defined in OctocatalogDiff::Catalog::Computed

Returns:

  • (String)

    Puppet version number

Raises:

  • (ArgumentError)

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/octocatalog-diff/util/puppetversion.rb', line 15

def self.puppet_version(puppet, options = {})
  raise ArgumentError, 'Puppet binary was not supplied' if puppet.nil?
  raise Errno::ENOENT, "Puppet binary #{puppet} doesn't exist" unless File.file?(puppet)

  sr_opts = {
    default_script: 'puppet/puppet.sh',
    override_script_path: options[:override_script_path]
  }

  script = OctocatalogDiff::Util::ScriptRunner.new(sr_opts)

  sr_run_opts = {
    :logger             => options[:logger],
    :working_dir        => File.dirname(puppet),
    :pass_env_vars      => options[:pass_env_vars],
    :argv               => '--version',
    'OCD_PUPPET_BINARY' => puppet
  }

  output = script.run(sr_run_opts)
  return Regexp.last_match(1) if output =~ /^([\d\.]+)\s*$/
  # :nocov:
  raise "Unable to determine Puppet version: #{script.output}"
  # :nocov:
end