summaryrefslogtreecommitdiff
path: root/puppet/modules/augeas/manifests/lens.pp
diff options
context:
space:
mode:
authorMicah <micah@leap.se>2016-07-12 16:46:07 -0400
committerMicah <micah@leap.se>2016-07-12 16:46:07 -0400
commit95374aacb857ed35c2fdfe6be7c0bfab86653963 (patch)
tree572645f7b8da9680d499f4380dcbab7e69575b69 /puppet/modules/augeas/manifests/lens.pp
parent4a11e48e397f1a7eb4c68a1dd1f9e3c5a11352f8 (diff)
git subrepo clone https://leap.se/git/puppet_augeas puppet/modules/augeas
subrepo: subdir: "puppet/modules/augeas" merged: "27e3359" upstream: origin: "https://leap.se/git/puppet_augeas" branch: "master" commit: "27e3359" git-subrepo: version: "0.3.0" origin: "https://github.com/ingydotnet/git-subrepo" commit: "1e79595" Change-Id: Ifa5c7daf3f1be1793c42f873a267b7498f5c6c0f
Diffstat (limited to 'puppet/modules/augeas/manifests/lens.pp')
-rw-r--r--puppet/modules/augeas/manifests/lens.pp79
1 files changed, 79 insertions, 0 deletions
diff --git a/puppet/modules/augeas/manifests/lens.pp b/puppet/modules/augeas/manifests/lens.pp
new file mode 100644
index 00000000..b5b9acd6
--- /dev/null
+++ b/puppet/modules/augeas/manifests/lens.pp
@@ -0,0 +1,79 @@
+# 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')
+ }
+
+ File {
+ owner => 'root',
+ group => 'root',
+ mode => '0644',
+ }
+
+ Exec {
+ path => $::path,
+ }
+
+ if (!$stock_since or versioncmp($::augeasversion, $stock_since) < 0) {
+
+ validate_re(
+ $augeas::lens_dir,
+ '/.*',
+ "'${augeas::lens_dir}' is not a valid path for lens ${name}"
+ )
+
+ $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],
+ }
+ }
+ }
+}