From 3c29d3545f746938ff926da7fdc616500f9d1ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuli=20Sepp=C3=A4nen?= Date: Thu, 11 Jun 2015 07:45:56 +0000 Subject: [PATCH 1/2] Fix some puppet-lint warnings --- manifests/parser.pp | 4 ++-- manifests/raw/ruleset.pp | 2 +- manifests/simple/ruleset.pp | 2 +- smoke/NOK_mismatching_action.pp | 2 +- smoke/OK_getent.pp | 2 +- smoke/OK_hybrid.pp | 2 +- smoke/OK_modules.pp | 2 +- smoke/OK_multiple_pdb.pp | 2 +- smoke/OK_notest.pp | 2 +- smoke/OK_raw.pp | 2 +- smoke/OK_s.pp | 2 +- smoke/OK_separate_action.pp | 2 +- smoke/OK_separate_rules.pp | 2 +- smoke/OK_separate_rules_and_actions.pp | 2 +- smoke/OK_simple.pp | 2 +- smoke/OK_simple_action.pp | 2 +- smoke/OK_simple_coerce.pp | 2 +- smoke/OK_simple_context.pp | 2 +- smoke/OK_simple_empty.pp | 2 +- smoke/OK_yum.pp | 2 +- 20 files changed, 21 insertions(+), 21 deletions(-) diff --git a/manifests/parser.pp b/manifests/parser.pp index db06733..9317174 100644 --- a/manifests/parser.pp +++ b/manifests/parser.pp @@ -4,10 +4,10 @@ $syslogng_modules = $::patterndb::syslogng_modules ) { if ! defined(Class['Patterndb']) { - include patterndb + include ::patterndb } if empty($syslogng_modules) { - $modules = '' + $modules = undef } else { $tmp = join($syslogng_modules,' --module=') $modules = "--module=${tmp}" diff --git a/manifests/raw/ruleset.pp b/manifests/raw/ruleset.pp index 1ae523d..dd38599 100644 --- a/manifests/raw/ruleset.pp +++ b/manifests/raw/ruleset.pp @@ -16,7 +16,7 @@ validate_bool($recurse) if ! defined(Class['Patterndb']) { - include patterndb + include ::patterndb } if ! defined(Patterndb::Parser[$parser]) { diff --git a/manifests/simple/ruleset.pp b/manifests/simple/ruleset.pp index 9dd6707..6289daa 100644 --- a/manifests/simple/ruleset.pp +++ b/manifests/simple/ruleset.pp @@ -11,7 +11,7 @@ ) { if ! defined(Class['Patterndb']) { - include patterndb + include ::patterndb } $patterns_a = string2array($patterns) diff --git a/smoke/NOK_mismatching_action.pp b/smoke/NOK_mismatching_action.pp index 52b9aa4..e7b877e 100644 --- a/smoke/NOK_mismatching_action.pp +++ b/smoke/NOK_mismatching_action.pp @@ -1,5 +1,5 @@ # -class { 'patterndb': +class { '::patterndb': base_dir => '/tmp/' } diff --git a/smoke/OK_getent.pp b/smoke/OK_getent.pp index 9f75b23..0552abf 100644 --- a/smoke/OK_getent.pp +++ b/smoke/OK_getent.pp @@ -1,5 +1,5 @@ # -class { 'patterndb': +class { '::patterndb': base_dir => '/tmp/', syslogng_modules => [ 'tfgetent' ] } diff --git a/smoke/OK_hybrid.pp b/smoke/OK_hybrid.pp index ca96d27..c7109cb 100644 --- a/smoke/OK_hybrid.pp +++ b/smoke/OK_hybrid.pp @@ -1,5 +1,5 @@ # -class { 'patterndb': +class { '::patterndb': base_dir => '/tmp/' } diff --git a/smoke/OK_modules.pp b/smoke/OK_modules.pp index e5ddfb3..c98ca5a 100644 --- a/smoke/OK_modules.pp +++ b/smoke/OK_modules.pp @@ -1,5 +1,5 @@ # -class { 'patterndb': +class { '::patterndb': base_dir => '/tmp/', syslogng_modules => [ 'basicfuncs' ] } diff --git a/smoke/OK_multiple_pdb.pp b/smoke/OK_multiple_pdb.pp index d89cba7..3c9c930 100644 --- a/smoke/OK_multiple_pdb.pp +++ b/smoke/OK_multiple_pdb.pp @@ -1,5 +1,5 @@ # -class { 'patterndb': +class { '::patterndb': base_dir => '/tmp/' } diff --git a/smoke/OK_notest.pp b/smoke/OK_notest.pp index a8fa593..73fcf47 100644 --- a/smoke/OK_notest.pp +++ b/smoke/OK_notest.pp @@ -1,5 +1,5 @@ # -class { 'patterndb': +class { '::patterndb': base_dir => '/tmp/', syslogng_modules => [ 'pdbtool_test_would_fail_with_this_module' ], test_before_deploy => false diff --git a/smoke/OK_raw.pp b/smoke/OK_raw.pp index 8deb8c4..aa1fbc6 100644 --- a/smoke/OK_raw.pp +++ b/smoke/OK_raw.pp @@ -1,5 +1,5 @@ # -class { 'patterndb': +class { '::patterndb': base_dir => '/tmp/', syslogng_modules => ['tfgetent'] } diff --git a/smoke/OK_s.pp b/smoke/OK_s.pp index 275cf0e..bdc2dc4 100644 --- a/smoke/OK_s.pp +++ b/smoke/OK_s.pp @@ -1,5 +1,5 @@ # -class { 'patterndb': +class { '::patterndb': base_dir => '/tmp/' } diff --git a/smoke/OK_separate_action.pp b/smoke/OK_separate_action.pp index 6918d8b..25b2b9e 100644 --- a/smoke/OK_separate_action.pp +++ b/smoke/OK_separate_action.pp @@ -1,5 +1,5 @@ # -class { 'patterndb': +class { '::patterndb': base_dir => '/tmp/' } diff --git a/smoke/OK_separate_rules.pp b/smoke/OK_separate_rules.pp index 8f1a92d..5869aab 100644 --- a/smoke/OK_separate_rules.pp +++ b/smoke/OK_separate_rules.pp @@ -1,5 +1,5 @@ # -class { 'patterndb': +class { '::patterndb': base_dir => '/tmp/' } diff --git a/smoke/OK_separate_rules_and_actions.pp b/smoke/OK_separate_rules_and_actions.pp index a3e2855..a8e35e5 100644 --- a/smoke/OK_separate_rules_and_actions.pp +++ b/smoke/OK_separate_rules_and_actions.pp @@ -1,5 +1,5 @@ # -class { 'patterndb': +class { '::patterndb': base_dir => '/tmp/' } diff --git a/smoke/OK_simple.pp b/smoke/OK_simple.pp index 2ca1ec3..6e8935e 100644 --- a/smoke/OK_simple.pp +++ b/smoke/OK_simple.pp @@ -1,5 +1,5 @@ # -class { 'patterndb': +class { '::patterndb': base_dir => '/tmp/' } diff --git a/smoke/OK_simple_action.pp b/smoke/OK_simple_action.pp index 9b1d81c..cd4a501 100644 --- a/smoke/OK_simple_action.pp +++ b/smoke/OK_simple_action.pp @@ -1,5 +1,5 @@ # -class { 'patterndb': +class { '::patterndb': base_dir => '/tmp/' } diff --git a/smoke/OK_simple_coerce.pp b/smoke/OK_simple_coerce.pp index 6a25158..ff07884 100644 --- a/smoke/OK_simple_coerce.pp +++ b/smoke/OK_simple_coerce.pp @@ -1,5 +1,5 @@ # -class { 'patterndb': +class { '::patterndb': base_dir => '/tmp/' } diff --git a/smoke/OK_simple_context.pp b/smoke/OK_simple_context.pp index 5e0b294..6777ae0 100644 --- a/smoke/OK_simple_context.pp +++ b/smoke/OK_simple_context.pp @@ -1,5 +1,5 @@ # -class { 'patterndb': +class { '::patterndb': base_dir => '/tmp/' } diff --git a/smoke/OK_simple_empty.pp b/smoke/OK_simple_empty.pp index b38c452..80bc2ca 100644 --- a/smoke/OK_simple_empty.pp +++ b/smoke/OK_simple_empty.pp @@ -1,5 +1,5 @@ # -class { 'patterndb': +class { '::patterndb': base_dir => '/tmp/' } diff --git a/smoke/OK_yum.pp b/smoke/OK_yum.pp index 2b37e41..fdf0169 100644 --- a/smoke/OK_yum.pp +++ b/smoke/OK_yum.pp @@ -1,5 +1,5 @@ # -class { 'patterndb': +class { '::patterndb': base_dir => '/tmp', syslogng_modules => [ 'tfgeoip', 'tfgetent' ], test_before_deploy => true, From 4dc26349f2ed925675ecaceaf2003957f1986f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuli=20Sepp=C3=A4nen?= Date: Thu, 11 Jun 2015 09:12:59 +0000 Subject: [PATCH 2/2] Fix installation of syslog-ng on Ubuntu 14.04 Syslog-ng package failed to install on Ubuntu 14.04 because syslog-ng-core package conflicted with the rsyslog package. The problem was fixed by ensuring that rsyslog is removed before syslog-ng installation is attempted. To make things cleaner and more manageable install and params subclasses were also added. --- README.md | 2 +- manifests/init.pp | 11 ++--------- manifests/install.pp | 24 ++++++++++++++++++++++++ manifests/params.pp | 21 +++++++++++++++++++++ 4 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 manifests/install.pp create mode 100644 manifests/params.pp diff --git a/README.md b/README.md index 805085a..d12513a 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ This module will manage the pattern databases of *syslog-ng* by using existing f Depending on the top-level configuration variables `$base_dir` and `$temp_dir`, this module will manage and execute the following elements in order: -0. (OPTIONAL) Manage package `syslog-ng` +0. (OPTIONAL) Manage package `syslog-ng` and remove the default syslog daemon (usually rsyslog) 1. Manage `$base_dir/etc/syslog-ng/patterndb.d` recursively 2. Manage the contents of the above directory using [existing](#defined-type-patterndbrawruleset) or [generated](#defined-type-patterndbsimpleruleset) patterndb *ruleset* files 3. Merge the contents of the latter using `pdbtool` into a temporary file `${temp_dir}/syslog-ng/patterndb/${parser}.xml` where `$parser` is the name of the *patterndb* (you can have as many as you want, *e.g.* for *staged parsing*. diff --git a/manifests/init.pp b/manifests/init.pp index f170406..01c4a16 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -14,16 +14,9 @@ validate_array($syslogng_modules) # package if $manage_package { - if is_string($package_name) { - $real_package_name = $package_name - } else { - case $::osfamily { - 'RedHat': { $real_package_name = 'syslog-ng' } - 'Debian': { $real_package_name = 'syslog-ng' } - default: { fail("unsupported osfamily: ${::osfamily}") } - } + class { '::patterndb::install': + package_name => $package_name, } - ensure_resource ( 'package', $real_package_name, { 'ensure' => 'installed' }) } ensure_resource ( 'file', $temp_dir, { ensure => directory } ) ensure_resource ( 'file', "${base_dir}/etc", { ensure => 'directory' } ) diff --git a/manifests/install.pp b/manifests/install.pp new file mode 100644 index 0000000..405641a --- /dev/null +++ b/manifests/install.pp @@ -0,0 +1,24 @@ +# +# == Class: patterndb::install +# +# Ensure that the default syslog is uninstalled and that syslog-ng is installed. +# +class patterndb::install ( + $package_name +) inherits patterndb::params +{ + if is_string($package_name) { + $real_package_name = $package_name + } else { + $real_package_name = $::patterndb::params::syslog_ng_package_name + } + + package { $::patterndb::params::default_syslog_package_name: + ensure => absent, + } + + package { $real_package_name: + ensure => installed, + require => Package[$::patterndb::params::default_syslog_package_name], + } +} diff --git a/manifests/params.pp b/manifests/params.pp new file mode 100644 index 0000000..d4b71e1 --- /dev/null +++ b/manifests/params.pp @@ -0,0 +1,21 @@ +# +# == Class: patterndb::params +# +# Defines some variables based on the operating system +# +class patterndb::params { + + case $::osfamily { + 'RedHat': { + $syslog_ng_package_name = 'syslog-ng' + $default_syslog_package_name = 'rsyslog' + } + 'Debian': { + $syslog_ng_package_name = 'syslog-ng' + $default_syslog_package_name = 'rsyslog' + } + default: { + fail("Unsupported operating system ${::osfamily}") + } + } +}