diff --git a/lib/puppet/provider/firewalld.rb b/lib/puppet/provider/firewalld.rb index 1d3f8b35..94d72840 100644 --- a/lib/puppet/provider/firewalld.rb +++ b/lib/puppet/provider/firewalld.rb @@ -8,10 +8,26 @@ class Puppet::Provider::Firewalld < Puppet::Provider def initialize(*args) if running.nil? + check_running_state + end + super + end + + def check_running_state + begin ret = self.class.execute_firewall_cmd(['--state'], nil, false, false) @running = ret.exitstatus == 0 ? true : false + rescue Puppet::MissingCommand => e + # This exception is caught in case the module is being run before + # the package provider has installed the firewalld package, if we + # cannot find the firewalld-cmd command then we silently continue + # leaving @running set to nil, this will cause it to be re-checked + # later in the execution process. + # + # See: https://github.com/crayfishx/puppet-firewalld/issues/96 + # + self.debug('Could not determine state of firewalld because the executable is not available') end - super end # v3.0.0 @@ -68,10 +84,12 @@ def reload_firewall end def offline? - @running == false + check_running_state if running.nil? + @running == false || @running.nil? end def online? + check_running_state if running.nil? @running == true end diff --git a/lib/puppet/provider/firewalld_zone/firewall_cmd.rb b/lib/puppet/provider/firewalld_zone/firewall_cmd.rb index f471f16c..bd275fb3 100644 --- a/lib/puppet/provider/firewalld_zone/firewall_cmd.rb +++ b/lib/puppet/provider/firewalld_zone/firewall_cmd.rb @@ -12,6 +12,15 @@ def exists? @resource[:zone] = @resource[:name] + + # If running is still set to nil then firewalld might not be installed yet, + # and we are probably calling this method from the generate method of the + # firewalld_zone type. We should just politely return false here as the + # module should install the package later in the puppet run, related to + # issue #96 + # + return false if running.nil? + execute_firewall_cmd(['--get-zones'], nil).split(" ").include?(@resource[:name]) end