Skip to content

Commit

Permalink
Merge pull request #3 from covermymeds/cje-puppet-lint
Browse files Browse the repository at this point in the history
License change and bug-fix
  • Loading branch information
cjestel committed Sep 10, 2015
2 parents 2c6b0b3 + 8f0d7e8 commit 8c27e63
Show file tree
Hide file tree
Showing 8 changed files with 764 additions and 73 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## 2015-09-08 Release 0.2.5
### Summary
License change and bug-fix

### Changes
- Fixed errors and warnings from puppet-lint
- Changed license to GPL-3.0+ to reflect initial source

## 2015-09-03 Release 0.2.4
### Summary
Bug-fix release

### Changes
- Changed version to match for release

## 2015-09-03 Release 0.2.3
### Summary
Bug-fix release
Expand Down
695 changes: 674 additions & 21 deletions LICENSE

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ PuppetSyntax.exclude_paths = exclude_paths
PuppetLint.configuration.fail_on_warnings
PuppetLint.configuration.with_context = true
PuppetLint.configuration.relative = true
PuppetLint.configuration.send('disable_class_inherits_from_params_class')

task :default => [:lint]
10 changes: 8 additions & 2 deletions manifests/databases.pp
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
define pgbouncer::databases(
# == define: pgbouncer::databases
#
# defined type that can be used to create the databases section in the config
# file
#
define pgbouncer::databases(
$databases = [],
) {

validate_array($databases)

unless empty($databases[0]) {
concat::fragment { "${databases[0]['dest_db']}_${databases[0]['auth_user']}":
$uniq_name = "${databases[0]['dest_db']}_${databases[0]['auth_user']}"
concat::fragment { $uniq_name:
target => $::pgbouncer::conffile,
content => template('pgbouncer/pgbouncer.ini.databases.part2.erb'),
order => '02',
Expand Down
80 changes: 47 additions & 33 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
#
# === Credits
#
# This module is loosely based on https://bitbucket.org/landcareresearch/puppet-pgbouncer
# This module is loosely based on
# https://bitbucket.org/landcareresearch/puppet-pgbouncer
#
# === Copyright
#
Expand All @@ -32,48 +33,55 @@
#
# === Parameters
#
# userlist is an empty array by default. You can create an array in hieradata like the
# example below or you can call the resource directly from a third party module
# userlist is an empty array by default. You can create an array in hieradata
# like the example below or you can call the resource directly from a third
# party module
# pgbouncer::userlist:
# - user: <user>
# password: <password>
# - user: <user2>
# password: <password2>
#
# databases is an empty array by default. You can create an array in hieradata like the
# example below or you can call the resource direclty from a third party module
# Set hieradata hash array for "pgbouncer::databases" to set values
# databases is an empty array by default. You can create an array in hieradata
# like the example below or you can call the resource direclty from a third
# party module Set hieradata hash array for "pgbouncer::databases" to set values
# Example:
# pgbouncer::databases
# - source_db: postgres
# host: localhost
# dest_db: postgres
# auth_user: postgres
#
# dbtmpfile is the temporary file the module uses to stitch together pieces using puppet
# concat. It's located in the tmp directory by default
# dbtmpfile is the temporary file the module uses to stitch together pieces
# using puppet concat. It's located in the tmp directory by default
#
# paramtmpfile is the temporary file the module uses to stitch together pieces using
# puppet concat. Its located in the tmp directory by default.
# paramtmpfile is the temporary file the module uses to stitch together pieces
# using puppet concat. Its located in the tmp directory by default.
#
# default_config_params is a hash of the necessary params needed to start pgbouncer. If
# you choose to override this, you must specify all of the default params and not just
# the one you want to override.
# default_config_params is a hash of the necessary params needed to start
# pgbouncer. If you choose to override this, you must specify all of the default
# params and not just the one you want to override.
#
# config_params is a hash that gets merged with the default params. If you want to override
# a single value, this would be the variable to do it in. All of the available params found
# in the below link can be added to the config from this hash.
# config_params is a hash that gets merged with the default params. If you want
# to override a single value, this would be the variable to do it in. All of the
# available params found in the below link can be added to the config from this
# hash.
# Link to pgbouncer doc: http://pgbouncer.projects.pgfoundry.org/doc/config.html
# Example:
# pgbouncer::config_params:
# port:8765
# dns_max_ttl: 16
#
# pgbouncer_package_name is the name of the package that should be installed. By
# default, this should be picked by the OS, but you can specify a name here if you'd like
# to override the package name. You could possibly use this to specify an older version
# as well.
# default, this should be picked by the OS, but you can specify a name here if
# you'd like to override the package name. You could possibly use this to
# specify an older version as well.
#
# conffile is the name of the configuration file
#
# userlist_file is the name of the auth_file where the userlist is stored
#
# deb_default_file is a file specific to ubuntu that loads a startup file
#
class pgbouncer (
$userlist = $pgbouncer::params::userlist,
Expand All @@ -83,6 +91,9 @@
$default_config_params = $pgbouncer::params::default_config_params,
$config_params = $pgbouncer::params::config_params,
$pgbouncer_package_name = $pgbouncer::params::pgbouncer_package_name,
$conffile = $pgbouncer::params::conffile,
$userlist_file = $pgbouncer::params::userlist_file,
$deb_default_file = $pgbouncer::params::deb_default_file,
) inherits pgbouncer::params {

# merge the defaults and custom params
Expand All @@ -93,37 +104,40 @@
# Same package name for both redhat based and debian based
package{ $pgbouncer_package_name:
ensure => installed,
require => [ Class['postgresql::repo::yum_postgresql_org'], Anchor['pgbouncer::begin'] ],
require => [
Class[
'postgresql::repo::yum_postgresql_org'],
Anchor['pgbouncer::begin']
],
}

# verify we have config file managed by concat
concat { "$conffile":
concat { $conffile:
ensure => present,
}

# verify we have auth_file managed by concat
concat { "$userlist_file":
concat { $userlist_file:
ensure => present,
}

# build the pgbouncer parameter piece of the config file
concat::fragment { "$paramtmpfile":
target => "$conffile",
concat::fragment { $paramtmpfile:
target => $conffile,
content => template('pgbouncer/pgbouncer.ini.param.part.erb'),
order => '03',
require => Package[$pgbouncer_package_name],
}

# check if debian
if $::osfamily == 'Debian' {
file{ "$deb_default_file":
file{ $deb_default_file:
ensure => file,
source => 'puppet:///modules/pgbouncer/pgbouncer',
require => Package[$_pgbouncer_package_name],
before => File["$userlist_file"],
require => Package[$pgbouncer_package_name],
before => File[$userlist_file],
}
}

# check if we have an authlist
if $userlist {
pgbouncer::userlist{ 'pgbouncer_module_userlist':
Expand All @@ -132,8 +146,8 @@
}

#build the databases base piece of the config file
concat::fragment { "$dbtmpfile":
target => "$conffile",
concat::fragment { $dbtmpfile:
target => $conffile,
content => template('pgbouncer/pgbouncer.ini.databases.part1.erb'),
order => '01',
}
Expand All @@ -142,12 +156,12 @@
if $databases {
pgbouncer::databases{ 'pgbouncer_module_databases':
databases => $databases,
}
}
}

service {'pgbouncer':
ensure => running,
subscribe => File["$userlist_file", "$conffile"],
subscribe => File[$userlist_file, $conffile],
}

anchor{'pgbouncer::end':
Expand Down
24 changes: 11 additions & 13 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,31 @@
$dbtmpfile = '/tmp/pgbouncer-dbtmpfile'
$paramtmpfile = '/tmp/pgbouncer-paramtmpfile'
$config_params = undef

# === Set OS specific variables (can be overridden by setting config_params) === #
$pgbouncer_package_name = 'pgbouncer'

# === Set OS specific variables === #
case $::osfamily {
'RedHat', 'Linux': {
$logfile = '/var/log/pgbouncer/pgbouncer.log'
$pidfile = '/var/run/pgbouncer/pgbouncer.pid'
$confdir = '/etc/pgbouncer'
$conffile = "$confdir/pgbouncer.ini"
$userlist_file = "$confdir/userlist.txt"
$conffile = "${confdir}/pgbouncer.ini"
$userlist_file = "${confdir}/userlist.txt"
$unix_socket_dir = '/tmp'
$pgbouncer_package_name = pick($pgbouncer_package_name,'pgbouncer')
}

'Debian': {
$logfile = '/var/log/postgresql/pgbouncer.log'
$pidfile = '/var/run/postgresql/pgbouncer.pid'
$confdir = '/etc/pgbouncer'
$conffile = "$confdir/pgbouncer.ini"
$userlist_file = "$confdir/userlist.txt"
$conffile = "${confdir}/pgbouncer.ini"
$userlist_file = "${confdir}/userlist.txt"
$unix_socket_dir = '/var/run/postgresql'
$pgbouncer_package_name = pick($pgbouncer_package_name,'pgbouncer')
$deb_default_file = '/etc/default/pgbouncer'
}

}

default: {
fail("Module ${module_name} is not supported on ${::operatingsystem}")
}
}
# === Setup default parameters === #
$default_config_params = {
logfile => $logfile,
Expand All @@ -53,5 +52,4 @@
max_client_conn => '1000',
default_pool_size => '20',
}

}
8 changes: 6 additions & 2 deletions manifests/userlist.pp
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
define pgbouncer::userlist (
# == define: pgbouncer::userlist
#
# defined type that can be used to create the userlist in the auth_file
#
define pgbouncer::userlist (
$auth_list = [],
) {

validate_array($auth_list)

concat::fragment { "$auth_list[0]['user']":
concat::fragment { $auth_list[0]['user']:
target => $::pgbouncer::userlist_file,
content => template('pgbouncer/userlist.txt.erb'),
order => '01',
Expand Down
4 changes: 2 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "covermymeds-pgbouncer",
"version": "0.2.4",
"version": "0.2.5",
"author": "CJ Estel",
"license": "MIT",
"license": "GPL-3.0+",
"summary": "Deploys pgbouncer",
"source": "https://github.com/covermymeds/puppet-pgbouncer.git",
"project_page": "https://github.com/covermymeds/puppet-pgbouncer",
Expand Down

0 comments on commit 8c27e63

Please sign in to comment.