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
# manage a config snippet
2
define nftables::config (
3
  Optional[String] $content = undef,
4
  Optional[Variant[String,Array[String,1]]] $source = undef,
5
) {
6
  if $content and $source {
7
    fail('Please pass only $content or $source, not both.')
8
  }
9

    
10
  $concat_name = "nftables-${name}"
11

    
12
  Package['nftables'] -> concat {
13
    $concat_name:
14
      path           => "/etc/nftables/puppet-preflight/${name}.nft",
15
      ensure_newline => true,
16
      owner          => root,
17
      group          => root,
18
      mode           => '0640',
19
  } ~> Exec['nft validate'] -> file {
20
    "/etc/nftables/puppet/${name}.nft":
21
      ensure => file,
22
      source => "/etc/nftables/puppet-preflight/${name}.nft",
23
      owner  => root,
24
      group  => root,
25
      mode   => '0640',
26
  } ~> Service['nftables']
27

    
28
  $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
  if $source {
38
    concat::fragment {
39
      "${concat_name}-body":
40
        target => $concat_name,
41
        order  => 98,
42
        source => $source,
43
    }
44
  } else {
45
    if $content {
46
      $_content = $content
47
    } else {
48
      $_content = "  include \"${name}-chain-*.nft\""
49
    }
50
    concat::fragment {
51
      "${concat_name}-body":
52
        target  => $concat_name,
53
        order   => '98',
54
        content => $_content,
55
    }
56
  }
57

    
58
  concat::fragment {
59
    "${concat_name}-footer":
60
      target  => $concat_name,
61
      order   => '99',
62
      content => '}',
63
  }
64
}