diff --git a/Modulefile b/Modulefile index 7747f6d8..fc56a348 100644 --- a/Modulefile +++ b/Modulefile @@ -10,6 +10,4 @@ project_page 'https://github.com/nibalizer/puppet-module-puppetboard' dependency 'puppetlabs/stdlib' dependency 'stankevich/python', '>= 1.1.4' dependency 'puppetlabs/vcsrepo', '>= 0.1.2' - - - +dependency 'puppetlabs/apache', '>=0.9.0' diff --git a/README.md b/README.md index 5827ef5f..9918fffb 100644 --- a/README.md +++ b/README.md @@ -12,16 +12,61 @@ https://github.com/nedap/puppetboard Usage ----- -Basically just pick a user and go. +Declare the base puppetboard manifest: +```puppet +class { 'puppetboard': } +``` - class { 'puppetboard': } +### Apache +If you want puppetboard accessible through Apache and you're able to use the +official `puppetlabs/apache` Puppet module, this module contains two classes +to help configuration. - class { 'puppetboard': - user => 'pboard', - } +The first, `puppetboard::apache::vhost`, will use the `apache::vhost` +defined-type to create a full virtual host. This is useful if you want +puppetboard to be available from http://pboard.example.com: +```puppet + +# Configure Apache on this server +class { 'apache': } + +# Configure Puppetboard +class { 'puppetboard': } + +# Access Puppetboard through pboard.example.com +class { 'puppetboard::apache::vhost': + vhost_name 'pboard.example.com', +} +``` + +The second, `puppetboard::apache::conf`, will create an entry in +`/etc/apache2/conf.d` (or `/etc/httpd/conf.d`, depending on your distribution). +This is useful if you simply want puppetboard accessible from +http://example.com/puppetboard: + +```puppet +# Configure Apache +# Ensure it does *not* purge configuration files +class { 'apache': + purge_configs => false, + mpm_module => 'prefork', + default_vhost => true, + default_mods => false, +} + +package { 'libapache2-mod-wsgi': + ensure => present, +} + +# Configure Puppetboard +class { 'puppetboard': } + +# Access Puppetboard from example.com/puppetboard +class { 'puppetboard::apache::conf': } +``` License ------- diff --git a/manifests/apache/conf.pp b/manifests/apache/conf.pp new file mode 100644 index 00000000..1f409b25 --- /dev/null +++ b/manifests/apache/conf.pp @@ -0,0 +1,29 @@ +# +# Make sure you have purge_configs set to false in your apache class! +# +class puppetboard::apache::conf ( + $wsgi_alias = '/puppetboard', + $threads = 5, + $user = $::puppetboard::params::user, + $group = $::puppetboard::params::group, +) inherits ::puppetboard::params { + + $docroot = "/home/${user}/puppetboard" + + file { "${docroot}/wsgi.py": + ensure => present, + content => template('puppetboard/wsgi.py.erb'), + owner => $user, + group => $group, + require => User[$user], + } + + file { "${::puppetboard::params::apache_confd}/puppetboard.conf": + ensure => present, + owner => 'root', + group => 'root', + content => template('puppetboard/apache/conf.erb'), + require => File["${docroot}/wsgi.py"], + notify => Service[$::puppetboard::params::apache_service], + } +} diff --git a/manifests/apache/vhost.pp b/manifests/apache/vhost.pp new file mode 100644 index 00000000..4640f469 --- /dev/null +++ b/manifests/apache/vhost.pp @@ -0,0 +1,40 @@ +class puppetboard::apache::vhost ( + $vhost_name, + $port = 5000, + $threads = 5, + $user = $::puppetboard::params::user, + $group = $::puppetboard::params::group, +) inherits ::puppetboard::params { + + $docroot = "/home/${user}/puppetboard", + + $wsgi_script_aliases = { + '/' => "${docroot}/wsgi.py", + } + + $wsgi_daemon_process_options = { + threads => $threads, + group => $group, + user => $user, + } + + file { "${docroot}/wsgi.py": + ensure => present, + content => template('puppetboard/wsgi.py.erb'), + owner => $user, + group => $group, + require => User[$user], + } + + ::apache::vhost { $vhost_name: + port => $port, + docroot => $docroot, + wsgi_daemon_process => $user, + wsgi_process_group => $group, + wsgi_script_aliases => $wsgi_script_aliases, + wsgi_daemon_process_options => $wsgi_daemon_process_options, + require => File["${docroot}/wsgi.py"], + notify => Service[$::puppetboard::params::apache_service], + } + +} diff --git a/manifests/init.pp b/manifests/init.pp index cb9b0c4c..123c533d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,73 +1,49 @@ # == Class: puppetboard # -# Full description of class puppetboard here. +# Base class for Puppetboard. +# Sets up the user and python environment. +# +# You should also use one of the apache classes as well. # # === Parameters # # Document parameters here. # -# [*sample_parameter*] -# Explanation of what this parameter affects and what it defaults to. -# e.g. "Specify one or more upstream ntp servers as an array." -# -# === Variables +# [*user*] +# Puppetboard system user. +# Defaults to 'puppetboard' # -# Here you should define a list of variables that this module would require. -# -# [*sample_variable*] -# Explanation of how this variable affects the funtion of this class and if it -# has a default. e.g. "The parameter enc_ntp_servers must be set by the -# External Node Classifier as a comma separated list of hostnames." (Note, -# global variables should not be used in preference to class parameters as of -# Puppet 2.6.) +# [*experimental*] +# Enable experimental features. +# Defaults to true # # === Examples # -# class { puppetboard: -# servers => [ 'pool.ntp.org', 'ntp.local.company.com' ] +# class { 'puppetboard': +# user => 'pboard', +# group => 'pboard', +# } -> +# class { 'puppetboard::apache::conf': +# user => 'pboard', +# group => 'pboard', # } # -# === Authors -# -# Author Name -# -# === Copyright -# -# Copyright 2013 Your name here, unless otherwise noted. -# class puppetboard( - $user = 'puppetboard', # The user to run puppetboard as - $mode = 'dev', # also can run it under mod_wsgi - $listen = '127.0.0.1', # listen locally or globally - $experimental = 'true', # enable experimental features - $port = '5000', - $manage_packages = 'true', - $manage_apache_service = 'true', -) { + $user = $::puppetboard::params::user, + $group = $::puppetboard::params::group, + $experimental = true, +) inherits ::puppetboard::params { - class { 'python': - version => 'system', - dev => true, - virtualenv => true, - } - - if $manage_packages == 'true' { - package { 'dtach': - ensure => present, - } - } - - group { 'puppetboard': + group { $group: ensure => present, } user { $user: ensure => present, - home => "/home/${user}", shell => '/bin/bash', managehome => true, - gid => 'puppetboard', - require => Group['puppetboard'], + gid => $group, + require => Group[$group], } vcsrepo { "/home/${user}/puppetboard": @@ -106,7 +82,7 @@ } } - if $experimental == 'true' { + if ($experimental) { file_line { 'puppetboard experimental': path => "/home/${user}/puppetboard/puppetboard/default_settings.py", line => 'PUPPETDB_EXPERIMENTAL=True', @@ -119,56 +95,4 @@ } } - if $mode == 'dev' { - - notify { "not starting puppetboard in dev mode": } - - } - - if $mode == 'wsgi' { - - case $::osfamily { - 'Debian': { - $apache_root = '/etc/apache2/sites-enabled' - $apache_service = 'apache2' - } - 'RedHat': { - $apache_root = '/etc/httpd/conf.d' - $apache_service = 'httpd' - } - default: { fail("This module is not supported on ${::osfamily}") } - } - - if $manage_packages == 'true' { - package { 'libapache2-mod-wsgi': - ensure => present, - } - } - - - file { "/home/${user}/puppetboard/wsgi.py": - ensure => present, - content => template('puppetboard/wsgi.py.erb'), - owner => $user, - group => 'puppetboard', - notify => Service[$apache_service], - } - - - file { "${apache_root}/puppetboard": - ensure => present, - content => template('puppetboard/puppetboard.erb'), - owner => $user, - group => 'puppetboard', - notify => Service[$apache_service], - } - - if $manage_apache_service == 'true' { - service { $apache_service: - ensure => running, - } - } - - } - } diff --git a/manifests/params.pp b/manifests/params.pp new file mode 100644 index 00000000..637a53d3 --- /dev/null +++ b/manifests/params.pp @@ -0,0 +1,17 @@ +class puppetboard::params { + + case $::osfamily { + 'Debian': { + $apache_confd = '/etc/apache2/conf.d' + $apache_service = 'apache2' + } + 'RedHat': { + $apache_confd = '/etc/httpd/conf.d' + $apache_service = 'httpd' + } + } + + $user = 'puppetboard' + $group = 'puppetboard' + +} diff --git a/templates/apache/conf.erb b/templates/apache/conf.erb new file mode 100644 index 00000000..55527ac2 --- /dev/null +++ b/templates/apache/conf.erb @@ -0,0 +1,9 @@ +WSGIDaemonProcess puppetboard user=<%= @user -%> group=<%= @user -%> threads=<%= @threads %> +WSGIScriptAlias <%= @wsgi_alias -%> <%= @docroot -%>/wsgi.py + +> + WSGIProcessGroup <%= @user %> + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + diff --git a/templates/puppetboard.erb b/templates/puppetboard.erb deleted file mode 100644 index 7463ff6d..00000000 --- a/templates/puppetboard.erb +++ /dev/null @@ -1,14 +0,0 @@ -Listen 5000 -:<%= @port %>> - ServerName puppetboard - - WSGIDaemonProcess puppetboard user=<%= @user %> group=puppetboard threads=5 - WSGIScriptAlias / /home/<%= @user %>/puppetboard/wsgi.py - - /puppetboard> - WSGIProcessGroup puppetboard - WSGIApplicationGroup %{GLOBAL} - Order deny,allow - Allow from all - - diff --git a/tests/init.pp b/tests/init.pp index ca012836..a4a6ff98 100644 --- a/tests/init.pp +++ b/tests/init.pp @@ -9,3 +9,4 @@ # Learn more about module testing here: http://docs.puppetlabs.com/guides/tests_smoke.html # include puppetboard +include puppetboard::apache::conf