Created
September 19, 2012 15:59
-
-
Save hcoyote/3750478 to your computer and use it in GitHub Desktop.
general puppet define to install a templated file somewhere.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this define allows us to inject a file into the catalog so it | |
# transfers over to the client in one big blog, instead of the client having to | |
# hit up the puppet file server for each file (meaning, 1 additional HTTP request | |
# per file) | |
define ops::install_file( | |
$ensure = present, | |
$filetype = "bin", | |
$module = $module_name, | |
$filename = $name, | |
) { | |
$allowed_types = ["bin","lib","deploy"] | |
if !($filetype in $allowed_types) { | |
$allowed_types_inspected = inline_template('<%= allowed_types.inspect %>') | |
fail("/usr/local/ops name=${name} filetype=${filetype} is not an allowed type: $allowed_types_inspected") | |
} | |
$mode = $filetype ? { | |
"bin" => 555, | |
"deploy" => 444, | |
default => 444, | |
} | |
$file = "/usr/local/ops/${filetype}/${filename}" | |
if ($ensure == "present") or ($ensure == present) { | |
# no need to make a specific require, since puppet auto requires file resources | |
include ops::directories | |
File { | |
owner => "root", | |
group => "root", | |
} | |
file { $file : | |
mode => $mode, | |
content => template("${module}/ops/${filetype}/${name}"), | |
} | |
} else { | |
file { $file : | |
ensure => "absent", | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment