Skip to content

Instantly share code, notes, and snippets.

@Sauraus
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sauraus/68745ad14107dc210c14 to your computer and use it in GitHub Desktop.
Save Sauraus/68745ad14107dc210c14 to your computer and use it in GitHub Desktop.
Force execution of provider
selinux_policy_module modulename do
action :deploy
end
end
file "#{path}/#{modulename}.pp" do
action :delete
end
selinux_policy_module modulename do
action :deploy
force true
end
file "#{path}/#{modulename}.pp" do
action :delete
end
selinux_policy_module modulename do
action :deploy
end
# Support whyrun
def whyrun_supported?
true
end
use_inline_resources
# Compile and deploy module (also upgrade)
action :deploy do
modulename="#{new_resource.name}"
attributesfile="#{Chef::Config[:file_cache_path]}/semodule-#{modulename}/#{modulename}.te"
directory "#{Chef::Config[:file_cache_path]}/semodule-#{modulename}" do
action :create
end
# only create the .te file if new_resource.content is not nil?
file attributesfile do
content new_resource.content
path "#{Chef::Config[:file_cache_path]}/semodule-#{modulename}"
only_if {use_selinux}
end unless new_resource.content.nil?
# We need to extract the module version from the .te file to ensure that we do not try to make & load the same version again
if match = IO.read(attributesfile).match(/policy_module *\(.*, *(.*)\)/i)
module_version = match.captures[0]
end
raise "No policy_module version defined in #{Chef::Config[:file_cache_path]}/semodule-#{modulename}/#{modulename}.te" if module_version.nil?
execute "semodule-deploy-#{new_resource.name}" do
command "/usr/bin/make -f /usr/share/selinux/devel/Makefile load"
only_if {new_resource.force or (module_version != shell_out("/usr/sbin/semodule -l | grep #{modulename} | cut -f2").stdout.chomp())}
cwd "#{Chef::Config[:file_cache_path]}/semodule-#{modulename}"
only_if {use_selinux}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment