module-puppetlabs-apt/lib/facter/apt_updates.rb
WolverineFan e7fee16589 Fix apt_has_updates fact not parsing apt-check output correctly
The /usr/lib/update-notifier/apt-check script returns its output
to STDERR but a recent change to the script redirects STDERR to
/dev/null.  This will cause the array to always be empty.

Combined with that problem, while we were checking for the result
being nil, we never checked for an invalid array.  As a result,
the apt_has_updates was always true and the apt_updates and
apt_security_updates facts were trying to read from an empty array
and failing.
2015-01-16 17:45:55 -05:00

42 lines
1 KiB
Ruby

apt_package_updates = nil
Facter.add("apt_has_updates") do
confine :osfamily => 'Debian'
if File.executable?("/usr/lib/update-notifier/apt-check")
apt_check_result = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check 2>&1')
if not apt_check_result.nil? and apt_check_result =~ /^\d+;\d+$/
apt_package_updates = apt_check_result.split(';')
end
end
setcode do
if not apt_package_updates.nil? and apt_package_updates.length == 2
apt_package_updates != ['0', '0']
end
end
end
Facter.add("apt_package_updates") do
confine :apt_has_updates => true
setcode do
packages = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check -p 2>&1').split("\n")
if Facter.version < '2.0.0'
packages.join(',')
else
packages
end
end
end
Facter.add("apt_updates") do
confine :apt_has_updates => true
setcode do
Integer(apt_package_updates[0])
end
end
Facter.add("apt_security_updates") do
confine :apt_has_updates => true
setcode do
Integer(apt_package_updates[1])
end
end