Skip to content

Commit 075ffa6

Browse files
committed
Allow unstructured facts in YAML (e.g. facter output)
1 parent 602f179 commit 075ffa6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/octocatalog-diff/facts/yaml.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,18 @@ def self.fact_retriever(options = {}, node = '')
2121
fact_file_data = fact_file_string.split(/\n/)
2222
fact_file_data[0] = '---' if fact_file_data[0] =~ /^---/
2323

24-
# Load and return the parsed fact file.
25-
result = YAML.load(fact_file_data.join("\n"))
24+
# Load the parsed fact file.
25+
parsed = YAML.load(fact_file_data.join("\n"))
26+
27+
# This is a handler for a YAML file that has just the facts and none of the
28+
# structure. For example if you saved the output of `facter -y` to a file and
29+
# are passing that in, this will work.
30+
result = if parsed.key?('name') && parsed.key?('values')
31+
parsed
32+
else
33+
{ 'name' => node || parsed['fqdn'] || '', 'values' => parsed }
34+
end
35+
2636
result['name'] = node unless node == ''
2737
result
2838
end

0 commit comments

Comments
 (0)