Projet

Général

Profil

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

root / manifests / config.pp @ 1a4f336e

Historique | Voir | Annoter | Télécharger (1,6 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
  String $prefix = 'custom-',
7
) {
8
  if $content and $source {
9
    fail('Please pass only $content or $source, not both.')
10
  }
11

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

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

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

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

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

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