Puppet Class: psick::hardening::generic

Defined in:
manifests/hardening/generic.pp

Overview

Generic class to remove unnecessary services and packages

Parameters:

  • packages_to_remove (Array) (defaults to: [])
  • services_to_remove (Array) (defaults to: [])
  • remove_default_packages (Boolean) (defaults to: false)
  • remove_default_services (Boolean) (defaults to: false)
  • manage (Boolean) (defaults to: $psick::manage)
  • noop_manage (Boolean) (defaults to: $psick::noop_manage)
  • noop_value (Boolean) (defaults to: $psick::noop_value)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'manifests/hardening/generic.pp', line 3

class psick::hardening::generic (
  Array $packages_to_remove        = [],
  Array $services_to_remove        = [],
  Boolean $remove_default_packages = false,
  Boolean $remove_default_services = false,
  Boolean $manage                  = $psick::manage,
  Boolean $noop_manage             = $psick::noop_manage,
  Boolean $noop_value              = $psick::noop_value,
) {
  if $manage {
    if $noop_manage {
      noop($noop_value)
    }

    $packages_default = []
    $services_default = $facts['os']['family'] ? {
      'RedHat'  => $facts['os']['release']['major'] ? {
        '5'      => [],
        '6'      => [],
        '7'      => [],
        default => [],
      },
      'Debian' => $facts['os']['release']['major'] ? {
        '6'      => [],
        '7'      => [],
        '8'      => [],
        '12.04'  => [],
        '14.04'  => [],
        '16.04'  => [],
        default => [],
      },
      default  => [],
    }

    $packages = $remove_default_packages ? {
      true  => $packages_to_remove + $packages_default,
      false => $packages_to_remove,
    }
    $services = $remove_default_services ? {
      true  => $services_to_remove + $services_default,
      false => $services_to_remove,
    }

    if $packages != [] {
      package { $packages:
        ensure => absent,
      }
    }
    $services.each |$svc| {
      service { $svc:
        ensure => stopped,
        enable => false,
      }
    }
  }
}