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

Manage package/service + linting fixes #9

Open
wants to merge 3 commits into
base: stable
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ This module includes a resource for adding scripts. This resource adds the scrip
Choose whether suricata should be present, absent, latest or version
Defaults to 'present'

#### `package_manage`

Choose whether this module should handle installation of Suricata

Defaults to true

#### `package_name`

Name of suricata package in repo
Expand All @@ -194,6 +200,12 @@ Directory of suricatas log files

Defaults to '/var/log/suricata'

### `service_manage`

Choose whether this module should manage Suricata service

Defaults to true

#### `service_ensure`

Choose whether suricata service is running or stopped
Expand Down
3 changes: 2 additions & 1 deletion data/common.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

suricata::ensure: "present"
suricata::package_manage: true
suricata::package_name: "suricata"
suricata::config_dir: "/etc/suricata"
suricata::config_name: "suricata.yaml"
suricata::log_dir: "/var/log/suricata"
suricata::service_manage: true
suricata::service_name: "suricata"
suricata::service_ensure: "running"
suricata::service_enable: true
Expand Down
16 changes: 13 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
# Choose whether suricata should be present, absent, latest or version
# Defaults to 'present'
#
# [*package_manage*]
# Choose whether this module will install Suricata service
# Defaults to true
#
# [*package_name*]
# Name of suricata package in repo
# Defaults to 'suricata'
Expand All @@ -24,6 +28,10 @@
# Directory of suricatas log files
# Defaults to '/var/log/suricata'
#
# [*service_manage*]
# Choose whether this module will manage the suricata service
# Defaults to true
#
# [*service_ensure*]
# Choose whether suricata service is running or stopped
# Defaults to 'running'
Expand Down Expand Up @@ -87,11 +95,13 @@

class suricata (
String $ensure,
Boolean $package_manage,
String $package_name,
Stdlib::Absolutepath $config_dir,
String $config_name,
Stdlib::Absolutepath $log_dir,
Enum['running', 'stopped'] $service_ensure,
Boolean $service_manage,
String $service_name,
Boolean $service_enable,
String $service_provider,
Expand Down Expand Up @@ -131,7 +141,7 @@
contain ::suricata::config
contain ::suricata::service

Class['::suricata::install']->
Class['::suricata::config']~>
Class['::suricata::service']
Class['::suricata::install']
-> Class['::suricata::config']
~> Class['::suricata::service']
}
57 changes: 30 additions & 27 deletions manifests/install.pp
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
class suricata::install {

case $::osfamily {
'RedHat': {
if $::suricata::configure_epel {
$pkg_require = Package['epel-release']
if $::suricata::package_manage {

package { 'epel-release':
ensure => installed,
}
} else { $pkg_require = undef }
}
'Debian': {
if $::operatingsystem == 'ubuntu' {
if $::suricata::ppa_source {
$pkg_require = Apt::Ppa[$::suricata::ppa_source]
case $::osfamily {
'RedHat': {
if $::suricata::configure_epel {
$pkg_require = Package['epel-release']

include ::apt
apt::ppa { $::suricata::ppa_source:
package_manage => true,
package { 'epel-release':
ensure => installed,
}
}
} else { $pkg_require = undef }
}
default: {
$pkg_require = undef
} else { $pkg_require = undef }
}
'Debian': {
if $::operatingsystem == 'ubuntu' {
if $::suricata::ppa_source {
$pkg_require = Apt::Ppa[$::suricata::ppa_source]

notice("Your operating system: ${::osfamily} is not support")
}
include ::apt
apt::ppa { $::suricata::ppa_source:
package_manage => true,
}
}
} else { $pkg_require = undef }
}
default: {
$pkg_require = undef

}
notice("Your operating system: ${::osfamily} is not support")
}

}

package { $::suricata::package_name:
ensure => $::suricata::ensure,
require => $pkg_require,
package { $::suricata::package_name:
ensure => $::suricata::ensure,
require => $pkg_require,
}
}
}
61 changes: 32 additions & 29 deletions manifests/service.pp
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
class suricata::service {

case $::suricata::service_provider {
'systemd': {

$systemd_path = $::operatingsystem ? {
/(Ubuntu|Debian)/ => '/lib/systemd/system',
default => '/usr/lib/systemd/system',
}
if $::suricata::service_manage {

case $::suricata::service_provider {
'systemd': {

$systemd_path = $::operatingsystem ? {
/(Ubuntu|Debian)/ => '/lib/systemd/system',
default => '/usr/lib/systemd/system',
}

$service_require = File["${systemd_path}/suricata.service"]
$service_require = File["${systemd_path}/suricata.service"]

file { "${systemd_path}/suricata.service":
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => epp('suricata/suricata.service.epp'),
file { "${systemd_path}/suricata.service":
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => epp('suricata/suricata.service.epp'),
}

exec { 'suriata-daemon-reload':
command => '/bin/systemctl daemon-reload',
subscribe => File["${systemd_path}/suricata.service"],
refreshonly => true,
notify => Service[$::suricata::service_name],
}
}
default: {
$service_require = undef

exec { 'Daemon-reload':
command => '/bin/systemctl daemon-reload',
subscribe => File["${systemd_path}/suricata.service"],
refreshonly => true,
notify => Service[$::suricata::service_name],
notice("Your ${::suricata::service_provider} is not supported")
}
}
default: {
$service_require = undef

notice("Your ${::suricata::service_provider} is not supported")
service { $::suricata::service_name:
ensure => $::suricata::service_ensure,
enable => $::suricata::service_enable,
provider => $::suricata::service_provider,
require => $service_require,
}
}

service { $::suricata::service_name:
ensure => $::suricata::service_ensure,
enable => $::suricata::service_enable,
provider => $::suricata::service_provider,
require => $service_require,
}

}