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

Refactor module #3

Merged
merged 3 commits into from
Oct 13, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Modulefile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
55 changes: 50 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
29 changes: 29 additions & 0 deletions manifests/apache/conf.pp
Original file line number Diff line number Diff line change
@@ -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],
}
}
40 changes: 40 additions & 0 deletions manifests/apache/vhost.pp
Original file line number Diff line number Diff line change
@@ -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],
}

}
126 changes: 25 additions & 101 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,73 +1,49 @@
# == Class: puppetboard
#
# Full description of class puppetboard here.
# Base class for Puppetboard.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're a hero for filling in the topdocs.

# 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 <[email protected]>
#
# === 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":
Expand Down Expand Up @@ -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',
Expand All @@ -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,
}
}

}

}
17 changes: 17 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -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'

}
9 changes: 9 additions & 0 deletions templates/apache/conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
WSGIDaemonProcess puppetboard user=<%= @user -%> group=<%= @user -%> threads=<%= @threads %>
WSGIScriptAlias <%= @wsgi_alias -%> <%= @docroot -%>/wsgi.py

<Directory <%= @docroot -%>>
WSGIProcessGroup <%= @user %>
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
14 changes: 0 additions & 14 deletions templates/puppetboard.erb

This file was deleted.

1 change: 1 addition & 0 deletions tests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
# Learn more about module testing here: http://docs.puppetlabs.com/guides/tests_smoke.html
#
include puppetboard
include puppetboard::apache::conf