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

Support for Puppet 8 #35

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
36 changes: 35 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
pkg/
.git/
.*.sw[op]
.metadata
.yardoc
.yardwarns
*.iml
/.bundle/
/.idea/
/.vagrant/
/coverage/
/bin/
/doc/
/Gemfile.local
/Gemfile.lock
/junit/
/log/
/pkg/
/spec/fixtures/manifests/
/spec/fixtures/modules/*
/tmp/
/vendor/
/.vendor/
/convert_report.txt
/update_report.txt
.DS_Store
.project
.envrc
/inventory.yaml
/spec/fixtures/litmus_inventory.yaml
.resource_types
.modules
.task_cache.json
.plan_cache.json
.rerun.json
bolt-debug.log
94 changes: 81 additions & 13 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,81 @@
source ENV['GEM_SOURCE'] || "https://rubygems.org"

if ENV.key?('PUPPET_VERSION')
puppetversion = "= #{ENV['PUPPET_VERSION']}"
else
puppetversion = ['>= 2.7']
end

gem 'rake'
gem 'puppet-lint'
gem 'rspec-puppet'
gem 'puppet', puppetversion
gem 'puppet-syntax'
source ENV['GEM_SOURCE'] || 'https://rubygems.org'

def location_for(place_or_version, fake_version = nil)
git_url_regex = %r{\A(?<url>(https?|git)[:@][^#]*)(#(?<branch>.*))?}
file_url_regex = %r{\Afile:\/\/(?<path>.*)}

if place_or_version && (git_url = place_or_version.match(git_url_regex))
[fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact
elsif place_or_version && (file_url = place_or_version.match(file_url_regex))
['>= 0', { path: File.expand_path(file_url[:path]), require: false }]
else
[place_or_version, { require: false }]
end
end

group :development do
gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "racc", '~> 1.4.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "deep_merge", '~> 1.2.2', require: false
gem "voxpupuli-puppet-lint-plugins", '~> 5.0', require: false
gem "facterdb", '~> 2.1', require: false if Gem::Requirement.create(['< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "facterdb", '~> 3.0', require: false if Gem::Requirement.create(['>= 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "metadata-json-lint", '~> 4.0', require: false
gem "json-schema", '< 5.1.1', require: false
gem "rspec-puppet-facts", '~> 4.0', require: false if Gem::Requirement.create(['< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "rspec-puppet-facts", '~> 5.0', require: false if Gem::Requirement.create(['>= 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "dependency_checker", '~> 1.0.0', require: false
gem "parallel_tests", '= 3.12.1', require: false
gem "pry", '~> 0.10', require: false
gem "simplecov-console", '~> 0.9', require: false
gem "puppet-debugger", '~> 1.0', require: false
gem "rubocop", '~> 1.50.0', require: false
gem "rubocop-performance", '= 1.16.0', require: false
gem "rubocop-rspec", '= 2.19.0', require: false
gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw]
end
group :development, :release_prep do
gem "puppet-strings", '~> 4.0', require: false
gem "puppetlabs_spec_helper", '~> 8.0', require: false
gem "puppet-blacksmith", '~> 7.0', require: false
end
group :system_tests do
gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw]
gem "CFPropertyList", '< 3.0.7', require: false, platforms: [:mswin, :mingw, :x64_mingw]
gem "serverspec", '~> 2.41', require: false
end

puppet_version = ENV['PUPPET_GEM_VERSION']
facter_version = ENV['FACTER_GEM_VERSION']
hiera_version = ENV['HIERA_GEM_VERSION']

gems = {}

gems['puppet'] = location_for(puppet_version)

# If facter or hiera versions have been specified via the environment
# variables

gems['facter'] = location_for(facter_version) if facter_version
gems['hiera'] = location_for(hiera_version) if hiera_version

gems.each do |gem_name, gem_params|
gem gem_name, *gem_params
end

# Evaluate Gemfile.local and ~/.gemfile if they exist
extra_gemfiles = [
"#{__FILE__}.local",
File.join(Dir.home, '.gemfile'),
]

extra_gemfiles.each do |gemfile|
if File.file?(gemfile) && File.readable?(gemfile)
eval(File.read(gemfile), binding)
end
end
# vim: syntax=ruby
27 changes: 14 additions & 13 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
require 'rake'
require 'puppet-lint/tasks/puppet-lint'
require 'puppet-syntax/tasks/puppet-syntax'
# frozen_string_literal: true

exclude_paths = [
'spec/**/*',
'pkg/**/*',
'tests/**/*'
]
require 'bundler'
require 'puppet_litmus/rake_tasks' if Gem.loaded_specs.key? 'puppet_litmus'
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-syntax/tasks/puppet-syntax'
require 'puppet-strings/tasks' if Gem.loaded_specs.key? 'puppet-strings'

PuppetSyntax.exclude_paths = exclude_paths
PuppetLint.configuration.fail_on_warnings
PuppetLint.configuration.with_context = true
PuppetLint.configuration.relative = true
PuppetLint.configuration.send('disable_relative')
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.send('disable_140chars')
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
PuppetLint.configuration.send('disable_autoloader_layout')
PuppetLint.configuration.send('disable_documentation')
PuppetLint.configuration.send('disable_single_quote_string_with_variables')
PuppetLint.configuration.fail_on_warnings = true
PuppetLint.configuration.ignore_paths = [".vendor/**/*.pp", ".bundle/**/*.pp", "pkg/**/*.pp", "spec/**/*.pp", "tests/**/*.pp", "types/**/*.pp", "vendor/**/*.pp"]

task :default => [:lint]
8 changes: 3 additions & 5 deletions manifests/databases.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
# defined type that can be used to create the databases section in the config
# file
#
define pgbouncer::databases(
$databases = [],
define pgbouncer::databases (
Array $databases = [],
) {

validate_array($databases)

unless empty($databases[0]) {
$uniq_name = "${databases[0]['dest_db']}_${databases[0]['auth_user']}"
concat::fragment { $uniq_name:
target => $::pgbouncer::conffile,
target => $pgbouncer::conffile,
content => template('pgbouncer/pgbouncer.ini.databases.part2.erb'),
order => '02',
}
Expand Down
55 changes: 26 additions & 29 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -81,45 +81,44 @@
# deb_default_file is a file specific to ubuntu that loads a startup file
#
class pgbouncer (
$userlist = $pgbouncer::params::userlist,
$databases = $pgbouncer::params::databases,
$paramtmpfile = $pgbouncer::params::paramtmpfile,
$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,
$service_start_with_system = $pgbouncer::params::service_start_with_system,
$user = $pgbouncer::params::user,
$group = $pgbouncer::params::group,
$require_repo = $pgbouncer::params::require_repo,
Array $userlist = $pgbouncer::params::userlist,
Array $databases = $pgbouncer::params::databases,
String $paramtmpfile = $pgbouncer::params::paramtmpfile,
Hash $default_config_params = $pgbouncer::params::default_config_params,
Hash $config_params = $pgbouncer::params::config_params,
String $pgbouncer_package_name = $pgbouncer::params::pgbouncer_package_name,
String $conffile = $pgbouncer::params::conffile,
String $userlist_file = $pgbouncer::params::userlist_file,
String $deb_default_file = $pgbouncer::params::deb_default_file,
Boolean $service_start_with_system = $pgbouncer::params::service_start_with_system,
String $user = $pgbouncer::params::user,
String $group = $pgbouncer::params::group,
Boolean $require_repo = $pgbouncer::params::require_repo,
) inherits pgbouncer::params {

# merge the defaults and custom params
$load_config_params = merge($default_config_params, $config_params)

anchor{'pgbouncer::begin':}
anchor { 'pgbouncer::begin': }

# Same package name for both redhat based and debian based
case $::osfamily {
case $facts['os']['family'] {
'RedHat', 'Linux': {
$package_require = $require_repo ? {
true => [ Class['postgresql::repo::yum_postgresql_org'], Anchor['pgbouncer::begin'] ],
true => [Class['postgresql::repo::yum_postgresql_org'], Anchor['pgbouncer::begin']],
false => Anchor['pgbouncer::begin'],
}
package{ $pgbouncer_package_name:
package { $pgbouncer_package_name:
ensure => installed,
require => $package_require,
}
}
'FreeBSD', 'Debian': {
package{ $pgbouncer_package_name:
package { $pgbouncer_package_name:
ensure => installed,
}
}
default: {
fail("Module ${module_name} is not supported on ${::operatingsystem}")
fail("Module ${module_name} is not supported on ${facts['os']['name']}")
}
}
# verify we have config file managed by concat
Expand Down Expand Up @@ -147,8 +146,8 @@
}

# check if debian
if $::osfamily == 'Debian' {
file{ $deb_default_file:
if $facts['os']['family'] == 'Debian' {
file { $deb_default_file:
ensure => file,
source => 'puppet:///modules/pgbouncer/pgbouncer',
require => Package[$pgbouncer_package_name],
Expand All @@ -157,8 +156,8 @@
}
# check if we have an authlist
if $userlist {
pgbouncer::userlist{ 'pgbouncer_module_userlist':
auth_list => $userlist,
pgbouncer::userlist { 'pgbouncer_module_userlist':
auth_list => $userlist,
paramtmpfile => $paramtmpfile,
}
}
Expand All @@ -179,20 +178,18 @@

# check if we have a database list and create entries
if $databases {
pgbouncer::databases{ 'pgbouncer_module_databases':
pgbouncer::databases { 'pgbouncer_module_databases':
databases => $databases,
}
}

validate_bool($service_start_with_system)

service {'pgbouncer':
service { 'pgbouncer':
ensure => running,
enable => $service_start_with_system,
subscribe => Concat[$userlist_file, $conffile],
}

anchor{'pgbouncer::end':
anchor { 'pgbouncer::end':
require => Service['pgbouncer'],
}
}
28 changes: 14 additions & 14 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
#
# Private class included by pgbouncer to set parameters
#
class pgbouncer::params {

$userlist = []
$databases = []
$paramtmpfile = '/tmp/pgbouncer-paramtmpfile'
$config_params = undef
$pgbouncer_package_name = 'pgbouncer'
$service_start_with_system = true
$user = 'pgbouncer'
$group = 'pgbouncer'
$require_repo = true

class pgbouncer::params (
Array $userlist = [],
Array $databases = [],
String $paramtmpfile = '/tmp/pgbouncer-paramtmpfile',
Hash $config_params = {},
String $pgbouncer_package_name = 'pgbouncer',
String $deb_default_file = '',
Boolean $service_start_with_system = true,
String $user = 'pgbouncer',
String $group = 'pgbouncer',
Boolean $require_repo = true,
) {
# === Set OS specific variables === #
case $::osfamily {
case $facts['os']['family'] {
'RedHat', 'Linux': {
$logfile = '/var/log/pgbouncer/pgbouncer.log'
$pidfile = '/var/run/pgbouncer/pgbouncer.pid'
Expand All @@ -42,7 +42,7 @@
$unix_socket_dir = '/tmp'
}
default: {
fail("Module ${module_name} is not supported on ${::operatingsystem}")
fail("Module ${module_name} is not supported on ${facts['os']['name']}")
}
}
# === Setup default parameters === #
Expand Down
14 changes: 5 additions & 9 deletions manifests/userlist.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@
#
# defined type that can be used to create the userlist in the auth_file
#
define pgbouncer::userlist(
$auth_list = [],
$paramtmpfile = '',
define pgbouncer::userlist (
Array $auth_list = [],
String $paramtmpfile = '',
) {

validate_array($auth_list)

concat::fragment { $auth_list[0]['user']:
target => $::pgbouncer::userlist_file,
target => $pgbouncer::userlist_file,
content => template('pgbouncer/userlist.txt.erb'),
order => '01',
}

concat::fragment { "${auth_list[0]['user']}_users":
target => $::pgbouncer::conffile,
target => $pgbouncer::conffile,
content => template('pgbouncer/pgbouncer.ini.users.part2.erb'),
order => '06',
}

}
Loading