summaryrefslogtreecommitdiff
path: root/puppet/modules
diff options
context:
space:
mode:
Diffstat (limited to 'puppet/modules')
-rw-r--r--puppet/modules/site_webapp/manifests/init.pp12
-rw-r--r--puppet/modules/try/README.md13
-rw-r--r--puppet/modules/try/manifests/file.pp51
-rw-r--r--puppet/modules/try/manifests/init.pp3
4 files changed, 72 insertions, 7 deletions
diff --git a/puppet/modules/site_webapp/manifests/init.pp b/puppet/modules/site_webapp/manifests/init.pp
index f0d6c90a..cdec1b6a 100644
--- a/puppet/modules/site_webapp/manifests/init.pp
+++ b/puppet/modules/site_webapp/manifests/init.pp
@@ -82,7 +82,9 @@ class site_webapp {
'/srv/leap-webapp/public/config/eip-service.json':
content => $eip_service,
owner => leap-webapp, group => leap-webapp, mode => '0644';
+ }
+ try::file {
'/srv/leap-webapp/public/favicon.ico':
ensure => 'link',
target => $webapp['favicon'];
@@ -94,14 +96,10 @@ class site_webapp {
'/srv/leap-webapp/app/assets/stylesheets/head.scss':
ensure => 'link',
target => $webapp['head_scss'];
- }
- if $webapp['img_dir'] != undef {
- file {
- '/srv/leap-webapp/public/img':
- ensure => 'link',
- target => $webapp['img_dir'];
- }
+ '/srv/leap-webapp/public/img':
+ ensure => 'link',
+ target => $webapp['img_dir'];
}
file {
diff --git a/puppet/modules/try/README.md b/puppet/modules/try/README.md
new file mode 100644
index 00000000..3888661e
--- /dev/null
+++ b/puppet/modules/try/README.md
@@ -0,0 +1,13 @@
+This module provides a "try" wrapper around common resource types.
+
+For example:
+
+ try::file {
+ '/path/to/file':
+ ensure => 'link',
+ target => $target;
+ }
+
+This will work just like `file`, but will silently fail if `$target` is undefined or the file does not exist.
+
+So far, only `file` type with symlinks works.
diff --git a/puppet/modules/try/manifests/file.pp b/puppet/modules/try/manifests/file.pp
new file mode 100644
index 00000000..406c0b7a
--- /dev/null
+++ b/puppet/modules/try/manifests/file.pp
@@ -0,0 +1,51 @@
+#
+# like built-in type "file", but gets gracefully ignored if the target does not exist or is undefined.
+#
+# /bin/true and /usr/bin/test are hardcoded to their paths in debian.
+#
+
+define try::file (
+ $ensure = undef,
+ $target = undef,
+ $restore = true) {
+
+ if $target != undef {
+ exec { "check_${name}":
+ command => "/bin/true",
+ onlyif => "/usr/bin/test -e '${target}'",
+ loglevel => info;
+ }
+ file { "$name":
+ ensure => $ensure,
+ target => $target,
+ require => Exec["check_${name}"],
+ loglevel => info;
+ }
+ }
+
+ #
+ # if the target does not exist (or is undef), and the file happens to be in a git repo,
+ # then restore the file to its original state.
+ #
+ if $target == undef or $restore {
+ $file_basename = basename($name)
+ $file_dirname = dirname($name)
+ $command = "git rev-parse && unlink '${name}'; git checkout -- '${file_basename}' && chown --reference='${file_dirname}' '${name}'; true"
+ debug($command)
+
+ if $target == undef {
+ exec { "restore_${name}":
+ command => $command,
+ cwd => $file_dirname,
+ loglevel => info;
+ }
+ } else {
+ exec { "restore_${name}":
+ unless => "/usr/bin/test -e '${target}'",
+ command => $command,
+ cwd => $file_dirname,
+ loglevel => info;
+ }
+ }
+ }
+}
diff --git a/puppet/modules/try/manifests/init.pp b/puppet/modules/try/manifests/init.pp
new file mode 100644
index 00000000..1d2108c9
--- /dev/null
+++ b/puppet/modules/try/manifests/init.pp
@@ -0,0 +1,3 @@
+class try {
+
+}