Skip to content

Instantly share code, notes, and snippets.

@heliocentric
Last active August 22, 2017 20:46
Show Gist options
  • Save heliocentric/e5967377279ce5518a9055fd7fc8bad1 to your computer and use it in GitHub Desktop.
Save heliocentric/e5967377279ce5518a9055fd7fc8bad1 to your computer and use it in GitHub Desktop.
file_backend.rb
Puppet::Functions.create_function(:'file_backend') do
dispatch :file_backend do
param "String", :key
param "Hash", :options
param "Puppet::LookupContext", :context
end
def file_backend(key, options, context)
if (options.key?("directory"))
dir = context.interpolate(options["directory"])
if (File.exists?("#{dir}/#{key}")
data = File.read("#{dir}/#{key}")
else
context.not_found
end
else
context.not_found
end
end
end
---
version: 5
defaults:
datadir: "data"
data_hash: "yaml_data"
hierarchy:
- name: "File Backend"
lookup_key: "file_backend"
options:
directory: '/data/hiera'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment