Skip to content

Commit

Permalink
update fact_on() from facter to puppet facts
Browse files Browse the repository at this point in the history
Both tools support json output. For `puppet facts` it's even the
default. `puppet facts` is the successor of `facter`. Newer facts, like
`puppetversion` are not shown by `facter`, but `puppet facts`.
  • Loading branch information
bastelfreak committed Dec 11, 2024
1 parent b137621 commit f54e9ab
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions lib/beaker_puppet_helpers/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,8 @@ def apply_manifest(manifest, opts = {}, &block)
def fact_on(host, name, opts = {})
raise(ArgumentError, "fact_on's `name` option must be a String. You provided a #{name.class}: '#{name}'") unless name.is_a?(String)

if opts.is_a?(Hash)
opts['json'] = nil
else
opts << ' --json'
end

result = on host, Beaker::Command.new('facter', [name], opts)
if result.is_a?(Array)
result.map { |res| JSON.parse(res.stdout)[name] }
else
JSON.parse(result.stdout)[name]
end
result = on host, Beaker::Command.new('puppet', 'facts', 'show', [name], opts)
JSON.parse(result.stdout)[name]
end

# Get a facter fact from the default host
Expand Down

0 comments on commit f54e9ab

Please sign in to comment.