Puppet Class: ipset

Defined in:
manifests/init.pp

Summary

module to install the ipset tooling and to manage individual ipsets

Overview

Parameters:

  • packages (Array[String[1]])

    The name of the package we want to install

  • service (String[1])

    The name of the service that we’re going to manage

  • service_ensure (Boolean)

    Desired state of the service. If true, the service will be running. If false, the service will be stopped

  • enable (Boolean)

    Boolean to decide if we want to have the service in autostart or not

  • firewall_service (Optional[Pattern[/\.service$/]]) (defaults to: undef)

    An optional service name. if provided, the ipsets will be configured before this. So your firewall will depend on the chains. The name should end with ‘.service`. This is only supported on systemd-based Operating Systems

  • package_ensure (Enum['present', 'absent', 'latest'])

    ensure parameter for the ipset package resource

  • config_path (Stdlib::Absolutepath)

    path to the directory for the ipsets

  • sets (Hash) (defaults to: {})

    Hash Hash of ‘ipset::set’ resources



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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'manifests/init.pp', line 27

class ipset (
  Array[String[1]] $packages,
  String[1] $service,
  Boolean $service_ensure,
  Boolean $enable,
  Enum['present', 'absent', 'latest'] $package_ensure,
  Stdlib::Absolutepath $config_path,
  Optional[Pattern[/\.service$/]] $firewall_service = undef,
  Hash $sets = {},
) {
  package { $ipset::packages:
    ensure => $package_ensure,
  }

  # create the config directory
  file { $config_path:
    ensure => 'directory',
  }

  # setup the helper scripts
  file { '/usr/local/bin/ipset_sync':
    ensure  => 'file',
    owner   => 'root',
    group   => 'root',
    mode    => '0754',
    content => file("${module_name}/ipset_sync"),
  }
  file { '/usr/local/bin/ipset_init':
    ensure  => 'file',
    owner   => 'root',
    group   => 'root',
    mode    => '0754',
    content => file("${module_name}/ipset_init"),
  }

  # configure custom unit file
  case $facts['service_provider'] {
    'systemd': {
      systemd::unit_file { "${service}.service":
        enable    => $enable,
        active    => $service_ensure,
        content   => epp("${module_name}/ipset.service.epp", {
            'firewall_service' => $firewall_service,
            'config_path'      => $config_path,
        }),
        subscribe => [File['/usr/local/bin/ipset_init'], File['/usr/local/bin/ipset_sync']],
      }
    }
    default: {
      fail('The ipset module only supports systemd based distributions')
    }
  }

  $sets.each |$set, $attributes| {
    ipset::set { $set:
      * => $attributes,
    }
  }
}