Hi Team, I looking for a puppet solution which co...
# puppet
n
Hi Team, I looking for a puppet solution which collects the diskspace of the respective server and if there is enough diskspace (let's say free 10gb) then download binaries and apply fixpack . Tried to do the same using custom facts but when puppet runs for the first time it's not applied because I think facts gets loaded or refreshed after second puppet run. Any suggestions please ?
j
We did this bit of madness on Windows since, yeah the agent on Windows does not return drive size. Ruby custom fact.
Facter.add(:win_storage_pws) do
confine osfamily: 'windows'
setcode do
def bytes_to_gbs (bytes) # creates a bytes to Gigabytes function
(bytes.to_f / 1000000000).round(2)
end
# This is the PowerShell call to retrieve the Storage info
storage = Facter::Core::Execution.execute("C:/Windows/system32/Windowspowershell/v1.0/powershell.exe -command \"Get-CimInstance -Classname win32_logicaldisk | ConvertTo-Json\"")
storage  = JSON.parse(storage)
storage.reduce({}) do |result,volume|
if volume['FreeSpace'] && volume['Size']
percentage_free = (volume['FreeSpace'].to_f*100/volume['Size'].to_f).round(2) #Calculate free space %
end
# Setup the facts for display
properties = {
'size_gb' => bytes_to_gbs(volume['Size']),
'freespace_gb' => bytes_to_gbs(volume['FreeSpace']),
'drive_type' => volume['DriveType'],
'percentage_free' => percentage_free
}
result.merge ({volume['Name'] => properties})
end
end
end
❤️ 1