sous-chefs / selinux

Development repository for the selinux cookbook
https://supermarket.chef.io/cookbooks/selinux
Apache License 2.0
58 stars 70 forks source link

`next unless value.nil?` not working #48

Closed silverl closed 7 years ago

silverl commented 7 years ago

Cookbook version

2.0.2

Chef-client version

13.1.31

Platform Details

CentOS 7.3

Scenario:

Trying to do setsebool commands using default['selinux']['booleans'] hash in my cookbook's attributes\default.rb file.

Steps to Reproduce:

I extracted your code and added logging to figure out which line was failing.

Here's what's in my attributes\default.rb file:

default['selinux']['booleans'] = {
  'httpd_can_sendmail' => true,
  'httpd_can_connect_ldap' => true,
  'httpd_can_network_memcache' => true
}

I've dumped the entire node into the logs to prove that my attribute booleans are getting set.

Here's my modified version of your code. I never see the "GOT HERE 2" message. It's as though the next unless value.nil? command always skips to the next iteration of the loop, no matter what. If I remove that line, things work fine.

log "============= GOT HERE =================="
node['selinux']['booleans'].each do |boolean, value|
  value = SELinuxServiceHelpers.selinux_bool(value)
  log "Is value of #{boolean} nil?: #{value.nil?}"
  next unless value.nil?
  log '================== GOT HERE 2 ================='
  log "Processing #{boolean} #{value}"
  script "boolean_#{boolean}" do
    interpreter 'bash'
    code "setsebool -P #{boolean} #{value}"
    not_if "getsebool #{boolean} |egrep -q \" #{value}\"$"
  end
end

Expected Result:

Expecting the setsebool script to run.

Actual Result:

* log[============= GOT HERE ==================] action write

         * log[Is value of httpd_can_sendmail nil?: false] action write

         * log[Is value of httpd_can_connect_ldap nil?: false] action write

         * log[Is value of httpd_can_network_memcache nil?: false] action write
iennae commented 7 years ago

Thanks for the PR. Version 2.0.3 of the cookbook has been released with your fix.