Merge branch 'redhat_helper' into 'master'

Add redhat helper and adapt selinux recipe to use it.

See merge request !385
This commit is contained in:
Marin Jankovski 2015-06-19 14:38:39 +00:00
commit cee73a2348
2 changed files with 47 additions and 1 deletions

View File

@ -221,3 +221,49 @@ module SingleQuoteHelper
end
end
class RedhatHelper
def self.system_is_rhel7?
platform_family == "rhel" && platform_version =~ /7\./
end
def self.platform_family
case platform
when /oracle/, /centos/, /redhat/, /scientific/, /enterpriseenterprise/, /amazon/, /xenserver/, /cloudlinux/, /ibm_powerkvm/, /parallels/
"rhel"
else
"not redhat"
end
end
def self.platform
contents = read_release_file
get_redhatish_platform(contents)
end
def self.platform_version
contents = read_release_file
get_redhatish_version(contents)
end
def self.read_release_file
if File.exists?("/etc/redhat-release")
contents = File.read("/etc/redhat-release").chomp
else
"not redhat"
end
end
# Taken from Ohai
# https://github.com/chef/ohai/blob/31f6415c853f3070b0399ac2eb09094eb81939d2/lib/ohai/plugins/linux/platform.rb#L23
def self.get_redhatish_platform(contents)
contents[/^Red Hat/i] ? "redhat" : contents[/(\w+)/i, 1].downcase
end
# Taken from Ohai
# https://github.com/chef/ohai/blob/31f6415c853f3070b0399ac2eb09094eb81939d2/lib/ohai/plugins/linux/platform.rb#L27
def self.get_redhatish_version(contents)
contents[/Rawhide/i] ? contents[/((\d+) \(Rawhide\))/i, 1].downcase : contents[/release ([\d\.]+)/, 1]
end
end

View File

@ -15,7 +15,7 @@
# limitations under the License.
#
if node["platform_family"] == "rhel" && node["platform_version"] =~ /7\./
if RedhatHelper.system_is_rhel7?
ssh_keygen_module = 'gitlab-7.2.0-ssh-keygen'
execute "semodule -i /opt/gitlab/embedded/selinux/rhel/7/#{ssh_keygen_module}.pp" do
not_if "semodule -l | grep '^#{ssh_keygen_module}\\s'"