Skip to content

Instantly share code, notes, and snippets.

@hlindberg
Last active January 13, 2023 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hlindberg/11a683c504172de7f2e3d455323d0d1f to your computer and use it in GitHub Desktop.
Save hlindberg/11a683c504172de7f2e3d455323d0d1f to your computer and use it in GitHub Desktop.
Puppet::Functions.create_function(:env_data) do
# @since 4.8.0
dispatch :env_data do
param 'Struct[{}]', :options
param 'Puppet::LookupContext', :context
end
def env_data(options, context)
ENV.to_h
end
end
@hlindberg
Copy link
Author

hlindberg commented Jan 12, 2023

This naive (and untested) implementation of a hiera 5 backend makes it possible to look up environment variables in puppet.
This backed is a data_hash type of backend and it is configured without "path" or "uri" in hiera.yaml. This means that function will be called once during the life of one hiera instance (one compilation). This means we do not have to worry about performance.

@hlindberg
Copy link
Author

The function is now updated to not accept any options. Earlier it required a "path".

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