Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add variables for RedHat os family #14

Closed
wants to merge 1 commit into from

Conversation

dobrerazvan
Copy link

No description provided.

@butlern
Copy link
Contributor

butlern commented Jun 13, 2018

ugh, i've been remiss. I believe we're addressing redhat compat in #15

@gramsa49
Copy link

gramsa49 commented Apr 2, 2019

I updated this module to support RHEL 7. This patch apples to v2.0.1
Not sure the proper way to submit a patch, please let me know the correct way if this is not it.

[t22hi2h@ha21t51en puppet-mdadm]$ git diff v2.0.1..3.0.17
diff --git a/lib/puppet/provider/mdadm/mdadm.rb b/lib/puppet/provider/mdadm/mdadm.rb
index 345a4df..7e721a0 100644
--- a/lib/puppet/provider/mdadm/mdadm.rb
+++ b/lib/puppet/provider/mdadm/mdadm.rb
@@ -4,9 +4,8 @@ Puppet::Type.type(:mdadm).provide(:mdadm) do
   desc "Manage Md raid devices"

   commands  :mdadm_cmd => 'mdadm',
-            :mkconf => '/usr/share/mdadm/mkconf',
             :yes => 'yes',
-            :update_initramfs => 'update-initramfs'
+            :update_initramfs => 'dracut'

   def create
     cmd = [command(:mdadm_cmd)]
@@ -68,10 +67,15 @@ Puppet::Type.type(:mdadm).provide(:mdadm) do
   private

   def make_conf
-    execute([command(:mkconf), "force-generate"])
+    raw = "MAILADDR root"
+    raw << "\n"
+    raw << "AUTO +imsm +1.x -all"
+    raw << "\n"
+    raw << execute([command(:mdadm_cmd), "--examine", "--scan"])
+    File.open('/etc/mdadm.conf', 'w') { |file| file.write(raw) }
   end

   def update_initramfs
-    execute([command(:update_initramfs), '-u'])
+    execute([command(:update_initramfs), '-f'])
   end
 end
diff --git a/lib/puppet/provider/mdadm/mkconf.rb b/lib/puppet/provider/mdadm/mkconf.rb
new file mode 100644
index 0000000..762d121
--- /dev/null
+++ b/lib/puppet/provider/mdadm/mkconf.rb
@@ -0,0 +1,77 @@
+require 'puppet'
+
+Puppet::Type.type(:mdadm).provide(:mkconf) do
+  desc "Manage Md raid devices"
+
+  commands  :mdadm_cmd => 'mdadm',
+            :mkconf => '/usr/share/mdadm/mkconf',
+            :yes => 'yes',
+            :update_initramfs => 'update-initramfs'
+
+  def create
+    cmd = [command(:mdadm_cmd)]
+    cmd << "--create"
+    cmd << "-e #{resource[:metadata]}"
+    cmd << resource.name
+    cmd << "--level=#{resource[:level]}"
+    cmd << "--raid-devices=#{resource[:active_devices] || resource[:devices].size}"
+    cmd << "--spare-devices=#{resource[:spare_devices]}" if resource[:spare_devices]
+    cmd << "--parity=#{resource[:parity]}" if resource[:parity]
+    cmd << "--chunk=#{resource[:chunk]}" if resource[:chunk]
+    cmd << resource[:devices]
+
+    if resource[:force]
+      cmd.unshift(command(:yes), "|")
+    end
+
+    execute(cmd.join(" "))
+    make_conf if resource[:generate_conf]
+    update_initramfs if resource[:update_initramfs]
+  end
+
+  def assemble
+    cmd = [command(:mdadm_cmd)]
+    cmd << "--assemble"
+    cmd << resource.name
+    cmd << resource[:devices]
+    execute(cmd)
+    make_conf if resource[:generate_conf]
+    update_initramfs if resource[:update_initramfs]
+  end
+
+  def stop
+    cmd = [command(:mdadm_cmd)]
+    cmd << "--misc"
+    cmd << "--stop"
+    cmd << resource.name
+    execute(cmd)
+    make_conf if resource[:generate_conf]
+    update_initramfs if resource[:update_initramfs]
+  end
+
+  def exists?
+    device_not_found = 4
+    begin
+      execute([command(:mdadm_cmd), "--detail", "--test", resource.name])
+      debug "Device #{resource.name} found"
+      return ($CHILD_STATUS.exitstatus == 0)
+    rescue Puppet::ExecutionFailure
+      if ($CHILD_STATUS.exitstatus == device_not_found)
+        debug "Device #{resource.name} not found"
+        return false
+      else
+        raise
+      end
+    end
+  end
+
+  private
+
+  def make_conf
+    execute([command(:mkconf), "force-generate"])
+  end
+
+  def update_initramfs
+    execute([command(:update_initramfs), '-u'])
+  end
+end
diff --git a/manifests/params.pp b/manifests/params.pp
index 40be485..b2244f1 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -28,6 +28,15 @@ class mdadm::params {

       $include_cron = true
     }
+    'RedHat': {
+      $package_name = 'mdadm'
+      $package_ensure = 'present'
+      $service_name = 'mdmonitor'
+      $service_ensure = 'running'
+      $service_manage = true
+      $service_hasstatus = true
+      $include_cron = true
+    }
     default: {
       fail("${::operatingsystem} not supported")
     }
diff --git a/metadata.json b/metadata.json
index ccd7fa5..1b1f079 100644
--- a/metadata.json
+++ b/metadata.json
@@ -21,6 +21,12 @@
         "9",
         "10"
       ]
+    },
+    {
+      "operatingsystem": "RedHat",
+      "operatingsystemrelease": [
+        "7"
+      ]
     }
   ],
   "requirements": [

@butlern
Copy link
Contributor

butlern commented Apr 2, 2019

it's kind of hard for me to understand what's going on here. I'm going to close this PR. If you would like to submit this patch, please see the Contributing section in the CONTRIBUTING.md.

@butlern butlern closed this Apr 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants