diff options
author | Micah Anderson <micah@riseup.net> | 2013-02-19 15:18:30 -0500 |
---|---|---|
committer | Micah Anderson <micah@riseup.net> | 2013-02-19 15:18:30 -0500 |
commit | 4dcc5f884cd22d0673f6493799ace2f03a9e66fe (patch) | |
tree | 3f3f5c217c40f3037c1b2a9cd8da3fe91fdd8389 /puppet/modules/try/manifests | |
parent | 253b765620961bbc9d96e8f3653b0b9693d29811 (diff) | |
parent | 2e5eec3856b58aaff0a2049599a6455e6ff91122 (diff) |
Merge remote-tracking branch 'origin/release/v0.2.0'0.2.0
Diffstat (limited to 'puppet/modules/try/manifests')
-rw-r--r-- | puppet/modules/try/manifests/file.pp | 51 | ||||
-rw-r--r-- | puppet/modules/try/manifests/init.pp | 3 |
2 files changed, 54 insertions, 0 deletions
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 { + +} |