Projet

Général

Profil

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

root / manifests / config.pp @ c5418fd3

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

1
# manage a config snippet
2
define nftables::config (
3
  Pattern[/^\w+-\w+$/] $tablespec = $title,
4
  Optional[String] $content = undef,
5
  Optional[Variant[String,Array[String,1]]] $source = undef,
6
) {
7
  if $content and $source {
8
    fail('Please pass only $content or $source, not both.')
9
  }
10

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

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

    
29
  $data = split($name, '-')
30

    
31
  concat::fragment {
32
    "${concat_name}-header":
33
      target  => $concat_name,
34
      order   => '00',
35
      content => "table ${data[0]} ${data[1]} {",
36
  }
37

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

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