commit 27af44443b5a6e98bd8d53d201233b511313df10
Author: Ewoud Kohl van Wijngaarden <e.kohlvanwijngaarden@oxilion.nl>
Date:   Thu Dec 5 15:30:53 2013 +0100

    Enable installation of plugins

diff --git a/manifests/params.pp b/manifests/params.pp
index 4567daa..0fce580 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -64,12 +64,14 @@ class foreman::params {
           $puppet_basedir  = '/usr/share/ruby/vendor_ruby/puppet'
           $yumcode = "f${::operatingsystemrelease}"
           $passenger_scl = undef
+          $plugin_prefix = 'rubygem-foreman_'
         }
         default: {
           $puppet_basedir = regsubst($::rubyversion, '^(\d+\.\d+).*$', '/usr/lib/ruby/site_ruby/\1/puppet')
           $yumcode = regsubst($::operatingsystemrelease, '^(\d+)\..*$', 'el\1')
           # add passenger::install::scl as EL uses SCL on Foreman 1.2+
           $passenger_scl = 'ruby193'
+          $plugin_prefix = 'ruby193-rubygem-foreman_'
         }
       }
     }
@@ -77,6 +79,7 @@ class foreman::params {
       $puppet_basedir  = '/usr/lib/ruby/vendor_ruby/puppet'
       $apache_conf_dir = '/etc/apache2/conf.d'
       $passenger_scl = undef
+      $plugin_prefix = 'ruby-foreman-'
     }
     Linux: {
       case $::operatingsystem {
@@ -86,6 +89,7 @@ class foreman::params {
           $yumcode = 'el6'
           # add passenger::install::scl as EL uses SCL on Foreman 1.2+
           $passenger_scl = 'ruby193'
+          $plugin_prefix = 'ruby193-rubygem-foreman_'
         }
         default: {
           fail("${::hostname}: This module does not support operatingsystem ${::operatingsystem}")
diff --git a/manifests/plugin.pp b/manifests/plugin.pp
new file mode 100644
index 0000000..08f61fa
--- /dev/null
+++ b/manifests/plugin.pp
@@ -0,0 +1,8 @@
+define foreman::plugin(
+  $package = "${foreman::plugin_prefix}${title}"
+) {
+  package { $package:
+    ensure => installed,
+    notify => Class['foreman::service'],
+  }
+}
diff --git a/manifests/plugin/puppetdb.pp b/manifests/plugin/puppetdb.pp
new file mode 100644
index 0000000..f24b49a
--- /dev/null
+++ b/manifests/plugin/puppetdb.pp
@@ -0,0 +1,34 @@
+class foreman::plugin::puppetdb {
+  case $::osfamily {
+    RedHat: {
+      case $::operatingsystem {
+        fedora: {
+          $package = 'rubygem-puppetdb_foreman'
+        }
+        default: {
+          $package = 'ruby193-rubygem-puppetdb_foreman'
+        }
+      }
+    }
+    Debian: {
+      $package = 'ruby-puppetdb_foreman'
+    }
+    Linux: {
+      case $::operatingsystem {
+        Amazon: {
+          $package = 'ruby193-rubygem-puppetdb_foreman'
+        }
+        default: {
+          fail("${::hostname}: puppetdb_foreman does not support operatingsystem ${::operatingsystem}")
+        }
+      }
+    }
+    default: {
+      fail("${::hostname}: puppetdb_foreman does not support osfamily ${::osfamily}")
+    }
+  }
+
+  foreman::plugin {'puppetdb':
+    package => $package,
+  }
+}
diff --git a/manifests/plugin/templates.pp b/manifests/plugin/templates.pp
new file mode 100644
index 0000000..fdabbf6
--- /dev/null
+++ b/manifests/plugin/templates.pp
@@ -0,0 +1,4 @@
+class foreman::plugin::templates {
+  foreman::plugin {'templates':
+  }
+}
diff --git a/spec/classes/foreman_plugin_puppetdb_spec.rb b/spec/classes/foreman_plugin_puppetdb_spec.rb
new file mode 100644
index 0000000..f187a66
--- /dev/null
+++ b/spec/classes/foreman_plugin_puppetdb_spec.rb
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+describe 'foreman::plugin::puppetdb' do
+  let :facts do {
+    :osfamily => 'Debian',
+  } end
+
+  it 'should call the plugin' do
+    should contain_foreman__plugin('puppetdb').with_package('ruby-puppetdb_foreman')
+  end
+end
+
diff --git a/spec/classes/foreman_plugin_templates_spec.rb b/spec/classes/foreman_plugin_templates_spec.rb
new file mode 100644
index 0000000..70eacdb
--- /dev/null
+++ b/spec/classes/foreman_plugin_templates_spec.rb
@@ -0,0 +1,7 @@
+require 'spec_helper'
+
+describe 'foreman::plugin::templates' do
+  it 'should call the plugin' do
+    should contain_foreman__plugin('templates')
+  end
+end
diff --git a/spec/defines/foreman_plugin_spec.rb b/spec/defines/foreman_plugin_spec.rb
new file mode 100644
index 0000000..6f08bf3
--- /dev/null
+++ b/spec/defines/foreman_plugin_spec.rb
@@ -0,0 +1,37 @@
+require 'spec_helper'
+
+describe 'foreman::plugin' do
+  let :title do 'myplugin' end
+
+  context 'no parameters' do
+    let :pre_condition do
+      'include foreman'
+    end
+
+    let :facts do {
+      :concat_basedir           => '/nonexistant',
+      :osfamily                 => 'RedHat',
+      :postgres_default_version => '8.4',
+    } end
+
+    it 'should install the correct package with notify' do
+      should contain_package('ruby193-rubygem-foreman_myplugin').with({
+        :ensure => 'installed',
+        :notify => 'Class[Foreman::Service]',
+      })
+    end
+  end
+
+  context 'with package parameter' do
+    let :params do {
+      :package => 'myplugin',
+    } end
+
+    it 'should install the correct package with notify' do
+      should contain_package('myplugin').with({
+        :ensure => 'installed',
+        :notify => 'Class[Foreman::Service]',
+      })
+    end
+  end
+end
