Class: RSpecSystem::Helpers::Facter

Inherits:
RSpecSystem::Helper
  • Object
show all
Defined in:
lib/rspec-system-puppet/helpers/facter.rb

Overview

Helper object behind RSpecSystemPuppet::Helpers#facter

Instance Method Summary collapse

Constructor Details

#initialize(opts, clr, &block) ⇒ Facter

Returns a new instance of Facter.



11
12
13
14
15
16
17
18
# File 'lib/rspec-system-puppet/helpers/facter.rb', line 11

def initialize(opts, clr, &block)
  # Defaults etc.
  opts = {
    :puppet => false,
  }.merge(opts)

  super(opts, clr, &block)
end

Instance Method Details

#executeRSpecSystem::Result

Gathers new results by executing the resource action

Returns:

  • (RSpecSystem::Result)

    raw execution results



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rspec-system-puppet/helpers/facter.rb', line 23

def execute
  node = opts[:node]
  
  cmd = "facter --yaml"
  cmd += " --puppet" if opts[:puppet]
  
  sh = shell :c => cmd, :n => node

  rd = sh.to_hash
  rd[:facts] = begin
    YAML::load(sh.stdout)
  rescue
  end

  rd
end