Xslt templates

Hi,

I need to use xslt templates to generate some files with chef. After much
googling and reading the doc I came up with:

execute “generate_xml” do
command "xsltproc -o file.out.xml file.xslt file.xml"
end

It works but is quite inappropriate. Is there a better solution?
Maybe there could be an xslt provider for the “template” resource?

Regards

On Tuesday, July 1, 2014 at 3:02 AM, greg3124@gmail.com wrote:

Hi,

I need to use xslt templates to generate some files with chef. After much
googling and reading the doc I came up with:

execute "generate_xml" do
command "xsltproc -o file.out.xml file.xslt file.xml"
end

It works but is quite inappropriate. Is there a better solution?
Maybe there could be an xslt provider for the "template" resource?

Regards
If you’re happy with this, then there’s no need to improve it. That said, this command will run every chef-client run (i.e., it’s not idempotent), so if you track chef’s changes to your system, or some other process is affected by changing the file every run, you want to see diffs when chef changes the file, or just have OCD about making your resources idempotent, then you might want to do something a bit more sophisticated.

There’s a couple things you could do. One that would be not too hard and probably work well enough is to make a LWRP where you use the shell_out method to run xsltproc and capture the output, then set that as the content parameter for a file resource. Alternatively, you could use a ruby library like nokogiri or ruby-xslt to actually do the xslt transform, which would be handy if you don’t expect to have xsltproc on every system, but then you need to deal with installing gems into chef which can be a pain (especially with nokogiri which uses C code to bridge ruby and the libxml2 library).

As for adding this to core chef, this isn’t a use case we see often, so I think it’d be best as a cookbook that you could maintain separately and publish on the cookbooks site.

--
Daniel DeLeo