summaryrefslogtreecommitdiff
path: root/manifests/lens.pp
blob: 723f21706eaa8693febf2482fd437979db75248b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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
/*

== Definition: augeas::lens

Deploy an Augeas lens (and its test file).
Check the lens (and run the unit tests) automatically and remove the files if
the checks fail.

Parameters:
- *ensure*: present/absent
- *lens_source*: the source for the lens
- *test_source*: optionally, the source for the test file.
- *stock_since*: optionally, indicate in which version of Augeas
  the lens became stock, so it will not be deployed above that version.

Example usage:

  augeas::lens { 'networkmanager':
    lens_source => 'puppet:///modules/networkmanager/lenses/networkmanager.aug',
    test_source => 'puppet:///modules/networkmanager/lenses/test_networkmanager.aug',
    stock_since => '1.0.0',
  }

*/

define augeas::lens (
  $lens_source,
  $ensure=present,
  $test_source=false,
  $stock_since=false,
) {
  if !defined(Class['augeas']) {
    fail('You must declare the augeas class before using augeas::lens')
  }

  if (!$stock_since or versioncmp($::augeasversion, $stock_since) < 0) {

    $lens_dest = "${augeas::lens_dir}/${name}.aug"
    $test_dest = "${augeas::lens_dir}/tests/test_${name}.aug"

    file { $lens_dest:
      ensure => $ensure,
      source => $lens_source,
    }

    exec { "Typecheck lens ${name}":
      command     => "augparse -I ${augeas::lens_dir} ${lens_dest} || (rm -f ${lens_dest} && exit 1)",
      refreshonly => true,
      subscribe   => File[$lens_dest],
    }

    if $test_source {
      file { $test_dest:
        ensure => $ensure,
        source => $test_source,
        notify => Exec["Test lens ${name}"],
      }

      exec { "Test lens ${name}":
        command     => "augparse -I ${augeas::lens_dir} ${test_dest} || (rm -f ${lens_dest} && rm -f ${test_dest} && exit 1)",
        refreshonly => true,
        subscribe   => File[$lens_dest, $test_dest],
      }
    }
  }
}