Skip to content

Instantly share code, notes, and snippets.

@albatrossflavour
Last active July 28, 2020 00:06
Show Gist options
  • Save albatrossflavour/cd6d5ed3071a4ddfe2317bce79139d17 to your computer and use it in GitHub Desktop.
Save albatrossflavour/cd6d5ed3071a4ddfe2317bce79139d17 to your computer and use it in GitHub Desktop.
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