Last active
March 1, 2017 13:24
-
-
Save cruftyoldsysadmin/4725d28d77f622dc4c1cea67e4b79093 to your computer and use it in GitHub Desktop.
Debbugging the nightmare that is Puppet ERB templates
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
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 |
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
#!/usr/bin/env ruby | |
require 'yaml' | |
# Loads the dump into a usable hash | |
file = YAML.load('/tmp/erb-dump.yaml') |
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
# 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, | |
} | |
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
<%# 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