From 0cd2a305f7fd9ba830a1fa3de25428ffa71d39f7 Mon Sep 17 00:00:00 2001 From: Micah Anderson Date: Wed, 1 Feb 2017 21:42:50 -0500 Subject: Fix fact for when shorewall is not yet installed. When a node has puppet run for the first time, shorewall may not be installed. In that case there are a few problems that appear in puppet4: 1. Warning: Facter: Could not retrieve fact='shorewall_major_version', resolution='': undefined method `split' for nil:NilClass This is because running 'shorewall version' fails and so results in a nil, and the split cannot be done on a nil. That is solved by first running the 'shorewall version' and setting a variable. If that variable is not nil, then we can split off of that 2. Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, 'versioncmp' parameter 'a' expects a String value, got Undef This happens because the shorewall_version is set to Undef, but we need to have it set to a String. So we set the variable to '-1' if it is not installed. --- lib/facter/shorewall_major_version.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/facter/shorewall_major_version.rb b/lib/facter/shorewall_major_version.rb index 0068b48..9c53ec2 100644 --- a/lib/facter/shorewall_major_version.rb +++ b/lib/facter/shorewall_major_version.rb @@ -1,5 +1,10 @@ Facter.add("shorewall_major_version") do setcode do - Facter::Util::Resolution.exec('shorewall version').split('.').first || nil + shorewall_version = Facter::Util::Resolution.exec('shorewall version') + if shorewall_version != nil + shorewall_major_version = shorewall_version.split('.').first + else + shorewall_major_version = '-1' + end end end -- cgit v1.2.3