Defined Type: etckeeper::ignore

Defined in:
manifests/ignore.pp

Overview

Add a glob pattern for the chosen VCS to ignore.

Examples:

Ignoring an example pattern

etckeeper::ignore { '*.foo':
  ensure => present,
}

Parameters:

  • ensure (Enum['present', 'absent']) (defaults to: 'present')
  • glob (String[1]) (defaults to: $title)

    The pattern to ignore.

See Also:

Since:

  • 1.2.0



14
15
16
17
18
19
20
21
22
23
24
25
26
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
# File 'manifests/ignore.pp', line 14

define etckeeper::ignore (
  Enum['present', 'absent'] $ensure = 'present',
  String[1]                 $glob   = $title,
) {

  if ! defined(Class['etckeeper']) {
    fail('You must include the etckeeper base class before using any etckeeper defined resources')
  }

  $vcs = $etckeeper::vcs

  case $vcs {
    'darcs': {
      # For darcs, convert the glob to a regex how etckeeper does it
      if $glob[0] == '*' {
        $start  = 1
        $prefix = '' # lint:ignore:empty_string_assignment
      } else {
        $start  = 0
        $prefix = '(^|/)'
      }
      if $glob[-1] == '*' {
        $end    = -2
        $suffix = '' # lint:ignore:empty_string_assignment
      } else {
        $end    = -1
        $suffix = '($|/)'
      }
      $_glob = suffix(prefix(regsubst(regsubst(regsubst($glob[$start, $end], '\.', '\\.', 'G'), '\*', '[^\\/]*', 'G'), '\?', '[^\\/]', 'G'), $prefix), $suffix)
    }
    'bzr': {
      # bzr doesn't need to excape anything
      $_glob = $glob
    }
    default: {
      # git and hg need to escape # characters
      $_glob = regsubst($glob, '#', '\\#', 'G')
    }
  }

  $vcs_ignore = {
    'bzr'   => '/etc/.bzrignore',
    'darcs' => '/etc/.darcsignore',
    'git'   => '/etc/.gitignore',
    'hg'    => '/etc/.hgignore',
  }

  # Relying on this to always append to the bottom of the file
  file_line { "${vcs_ignore[$vcs]} ${glob}":
    ensure  => $ensure,
    path    => $vcs_ignore[$vcs],
    line    => $_glob,
    require => Class['etckeeper::config'],
  }
}