Skip to content

Instantly share code, notes, and snippets.

@cruftyoldsysadmin
Last active March 1, 2017 13:24
Show Gist options
  • Save cruftyoldsysadmin/4725d28d77f622dc4c1cea67e4b79093 to your computer and use it in GitHub Desktop.
Save cruftyoldsysadmin/4725d28d77f622dc4c1cea67e4b79093 to your computer and use it in GitHub Desktop.
Debbugging the nightmare that is Puppet ERB templates
If you have ever done *anything* with Puppet templates, you know how ugly it is to debug.
This Gist will help improve debugging and reduce guesswork. The main problem I always run into when debugging
ERB templates is grokking variable access.
I have included two code snippets:
- erb-dump.pp # Puppet manifest
- erb-dump.yaml.erb # ERB template to dump the entire namespace available to the template to /tmp/erb-dump.yaml
- erb-dump.rb # loads the yaml dump into a usable ruby hash
#!/usr/bin/env ruby
require 'yaml'
# Loads the dump into a usable hash
file = YAML.load('/tmp/erb-dump.yaml')
# Creates /tmp/erb-dump.yaml from the erb-dump.template
file {'/tmp/erb-dump.yaml':
content = template ('erb-dump.yaml.erb'),
ensure = 'present'
mode = '0644',
owner = 'puppet',
group = 'puppet,
}
<%# If you have ever done *anything* with Puppet templates, you know how ugly it is to debug
This Gist will help fix that to somewhat easier. -%>
<%= scope.to_hash.reject { |k,v| !( k.is_a?(String) && v.is_a?(String) ) }.to_yaml %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment