Module: Chef::SELinux::CommonHelpers

Defined in:
lib/chef/resource/selinux/common_helpers.rb

Instance Method Summary collapse

Instance Method Details

#selinux_activate_required?Boolean

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/chef/resource/selinux/common_helpers.rb', line 40

def selinux_activate_required?
  return false unless platform_family?("debian")

  !File.read("/etc/default/grub").match?("security=selinux")
end

#selinux_disabled?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/chef/resource/selinux/common_helpers.rb', line 17

def selinux_disabled?
  selinux_state.eql?(:disabled)
end

#selinux_enforcing?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/chef/resource/selinux/common_helpers.rb', line 21

def selinux_enforcing?
  selinux_state.eql?(:enforcing)
end

#selinux_permissive?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/chef/resource/selinux/common_helpers.rb', line 25

def selinux_permissive?
  selinux_state.eql?(:permissive)
end

#selinux_stateObject



33
34
35
36
37
38
# File 'lib/chef/resource/selinux/common_helpers.rb', line 33

def selinux_state
  state = shell_out!("getenforce").stdout.strip.downcase.to_sym
  raise "Got unknown SELinux state #{state}" unless %i{disabled enforcing permissive}.include?(state)

  state
end

#state_change_reboot_required?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/chef/resource/selinux/common_helpers.rb', line 29

def state_change_reboot_required?
  (selinux_disabled? && %i{enforcing permissive}.include?(action)) || ((selinux_enforcing? || selinux_permissive?) && action == :disabled)
end