Skip to content

Instantly share code, notes, and snippets.

@binford2k
Last active February 12, 2019 06:06
Show Gist options
  • Save binford2k/9adf86c70b4075fc1668048bcb3f113c to your computer and use it in GitHub Desktop.
Save binford2k/9adf86c70b4075fc1668048bcb3f113c to your computer and use it in GitHub Desktop.
# <module>/functions/deferred_epp.pp
# note: depends on puppetlabs/stdlib
function deferred_epp(String $template, Hash $variables) >> Deferred {
if($template[0] == '/') {
$path = $template
}
else {
$parts = $template.split('/')
$mod = get_module_path($parts[0])
$file = $parts[1,-1].join('/')
$path = "${mod}/templates/${file}"
}
Deferred("inline_epp", [file($path), $variables])
}
@binford2k
Copy link
Author

$variables = {
    'password' => Deferred('vault_lookup::lookup',
                    ["secret/test", 'https://vault.docker:8200']),
}

file { '/etc/secret.conf':
    ensure  => file,
    owner   => 'root',
    mode    => '0600',
    content => deferred_epp('mod/template.epp', $variables),
}

@hlindberg
Copy link

We should add find_template() function analog to find_file() in puppet. (The underlying implementation in Puppet::Pops::Parser::Files already supports finding template in the method find_template(template, environment))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment