Last active
July 28, 2020 00:06
-
-
Save albatrossflavour/cd6d5ed3071a4ddfe2317bce79139d17 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "json" | |
Facter.add('vra') do | |
setcode do | |
data = {} | |
if Facter.value(:kernel) == 'windows' | |
json_file = 'C:\ProgramData\PuppetLabs\facter\facts.d\puppet_vra_facts.json' | |
else | |
json_file = '/etc/puppetlabs/facter/facts.d/puppet_vra_facts.json' | |
end | |
if File.file?(json_file) | |
file = open(json_file) | |
json = file.read | |
parsed = JSON.parse(json) | |
count = (1..50).to_a | |
count.each do | x | | |
if parsed['puppet_vra_properties']['VMware.Attribute' + x.to_s + '.Name'] | |
attribute = 'VMware.Attribute' + x.to_s | |
key = parsed['puppet_vra_properties'][attribute + '.Name'].downcase.tr(" ","_").delete('()') | |
data[key] = parsed['puppet_vra_properties'][attribute + '.Value'] | |
end | |
end | |
data | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment