Ask Your Question

How do I check for deprecated variable references in templates?

asked 2014-05-27 11:03:13 -0500

gertvdijk gravatar image

updated 2014-05-27 11:04:26 -0500

Suppose I have a template referencing a fact like this (deprecated):

listen=<%= ipaddress %>

Then this will generate a warning in the Puppet master log:

Variable access via 'ipaddress' is deprecated. Use '@ipaddress' instead. template[/path/to/template.erb]:2

Fine, I know where to fix this now. However, it does not parse all manifests/templates, but only for a given node. I need to verify all templates, preferably offline without the need to run the agent everywhere.

From the Puppet documentation I can check for valid syntax using

erb -P -x -T '-' mytemplate.erb | ruby -c

However, it does not spot the error then:

erb -x -T '-' /path/to/template.erb | ruby -c
Syntax OK

How can I check this "offline" reliably?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-08-05 13:28:43 -0500

This will produce some false positives, but should catch all offending variable references.

grep -RoP '<%=[^%>|@]*%>' /path/to/puppet/manifests
edit flag offensive delete link more

answered 2014-08-26 12:49:19 -0500

WhatsARanjit gravatar image

If you'd like to test that your Puppet code actually produces what you're looking for, you can either run it in a sandbox and manually take a look, or look into writing rspec-puppet tests to check for you.

edit flag offensive delete link more


Also whipped up this gist for another question:

WhatsARanjit gravatar imageWhatsARanjit ( 2014-08-26 13:38:26 -0500 )edit

You're not describing *how* to run it in a 'sandbox'. I don't know what a sanbox is in Puppet terms. And rspec tests are nice, but not doing what I ask for; they don't test specific node-specific templates! Oh and the gist link gives 404. So overall this is not an answer in my opinion.

gertvdijk gravatar imagegertvdijk ( 2014-08-27 02:38:51 -0500 )edit

Running in a sandbox meaning boot up a throwaway VM and use puppet apply to test things locally. After the templates get written into real files, check the files to see that they came out correctly.

WhatsARanjit gravatar imageWhatsARanjit ( 2014-08-27 08:55:20 -0500 )edit

I don't want to apply the configs anywhere else because that would overwrite the exported node details in puppetdb and I would have a duplicate certname in my Puppet CA. It's gonna be DAMN ugly to test it like that. Am I missing something?

gertvdijk gravatar imagegertvdijk ( 2014-08-27 09:24:02 -0500 )edit

The problem is that the template is in this case working as expected, but throws deprecated errors in the puppet masters log. A (preferably easy) way to check this on, as an example, a git pre-commit-hook is what at least I am looking for with this.

mld gravatar imagemld ( 2014-08-27 09:24:10 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2014-05-27 11:03:13 -0500

Seen: 971 times

Last updated: Aug 26 '14