Module: Beaker::DSL::Helpers::FacterHelpers
- Included in:
- BeakerPuppet
- Defined in:
- lib/beaker-puppet/helpers/facter_helpers.rb
Overview
Methods that help you interact with your facter installation, facter must be installed for these methods to execute correctly
Instance Method Summary collapse
-
#fact(name, opts = {}) ⇒ Object
Get a facter fact from the default host.
-
#fact_on(host, name, opts = {}) ⇒ Object
Get a facter fact from a provided host.
Instance Method Details
#fact(name, opts = {}) ⇒ Object
Get a facter fact from the default host
60 61 62 |
# File 'lib/beaker-puppet/helpers/facter_helpers.rb', line 60 def fact(name, opts = {}) fact_on(default, name, opts) end |
#fact_on(host, name, opts = {}) ⇒ Object
Get a facter fact from a provided host
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/beaker-puppet/helpers/facter_helpers.rb', line 38 def fact_on(host, name, opts = {}) unless name.is_a?(String) raise(ArgumentError, "fact_on's `name` option must be a String. You provided a #{name.class}: '#{name}'") end if opts.is_a?(Hash) opts.merge!({ json: nil }) else opts << ' --json' end result = on host, facter("\"#{name}\"", opts) if result.is_a?(Array) result.map { |res| JSON.parse(res.stdout)[name] } else JSON.parse(result.stdout)[name] end end |