Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / manifests / config.pp @ 294a38ff

Historique | Voir | Annoter | Télécharger (1,5 ko)

1 0ba57c66 mh
# manage a config snippet
2 11bf7237 Steve Traylen
define nftables::config (
3 31b17627 Steve Traylen
  Optional[String] $content = undef,
4
  Optional[Variant[String,Array[String,1]]] $source = undef,
5 11bf7237 Steve Traylen
) {
6 294a38ff Nacho Barrientos
  if $content and $source {
7
    fail('Please pass only $content or $source, not both.')
8
  }
9
10 e4c32222 Nacho Barrientos
  $concat_name = "nftables-${name}"
11
12 11bf7237 Steve Traylen
  Package['nftables'] -> concat {
13 e4c32222 Nacho Barrientos
    $concat_name:
14 30462da1 Steve Traylen
      path           => "/etc/nftables/puppet-preflight/${name}.nft",
15 e4c32222 Nacho Barrientos
      ensure_newline => true,
16
      owner          => root,
17
      group          => root,
18
      mode           => '0640',
19 11bf7237 Steve Traylen
  } ~> Exec['nft validate'] -> file {
20 30462da1 Steve Traylen
    "/etc/nftables/puppet/${name}.nft":
21 11bf7237 Steve Traylen
      ensure => file,
22
      source => "/etc/nftables/puppet-preflight/${name}.nft",
23
      owner  => root,
24
      group  => root,
25
      mode   => '0640',
26 0ba57c66 mh
  } ~> Service['nftables']
27
28 e4c32222 Nacho Barrientos
  $data = split($name, '-')
29
30
  concat::fragment {
31
    "${concat_name}-header":
32
      target  => $concat_name,
33
      order   => '00',
34
      content => "table ${data[0]} ${data[1]} {",
35
  }
36
37 0ba57c66 mh
  if $source {
38 e4c32222 Nacho Barrientos
    concat::fragment {
39
      "${concat_name}-body":
40
        target => $concat_name,
41
        order  => 98,
42
        source => $source,
43 0ba57c66 mh
    }
44
  } else {
45 fcb1d356 Nacho Barrientos
    if $content {
46
      $_content = $content
47
    } else {
48
      $_content = "  include \"${name}-chain-*.nft\""
49
    }
50 e4c32222 Nacho Barrientos
    concat::fragment {
51
      "${concat_name}-body":
52
        target  => $concat_name,
53
        order   => '98',
54 fcb1d356 Nacho Barrientos
        content => $_content,
55 0ba57c66 mh
    }
56
  }
57 e4c32222 Nacho Barrientos
58
  concat::fragment {
59
    "${concat_name}-footer":
60
      target  => $concat_name,
61
      order   => '99',
62
      content => '}',
63
  }
64 0ba57c66 mh
}