Including erubis fragments within a template

Dear Chefs,

I work on almost basis with the Enterprise Java container known as JBoss AS
7. JBoss’s main configuration file, standalone-full.xml, is a whopping 553
lines long. While it is very long, it actually quite cleanly structured,
especially when compared to something like sendmail.cf

Templating such a large file is a mega PITA. JBoss AS 7 is nicely
componentized so that you can easily turn on and off modules. This process
would be a billion times easier and more readable if I could include
fragments within and erubis template like this:

<?xml version='1.0' encoding='UTF-8'?> <% if @infinispan -%> <% end -%> <% if @webservices -%> <% end -%> <% if @infinispan include_template "infinispan.xml.erb" end -%> <% if @webservices include_template "webservices.xml.erb" end -%> ......

As you can see, this is far more readable than adding complex logic to
already large file

Is this at all feasible currently in Chef? It would make life a lot easier
for me

Hi Bryan,

Here's a segment of a configuration file that uses 'if' statements:
https://github.com/DataDog/cookbooks/blob/master/datadog/templates/default/datadog.conf.erb#L21-53
(Do as I say, not as I do: the node attribute accessors should
probably be strings vs symbols, but that's a future improvement).

My template is referencing directly against node attributes, you may
with to pass variables to the template resource for config items that
aren't exactly node attributes.

More on templates: http://wiki.opscode.com/display/chef/Templates

Best,
-M

On Thu, Jun 28, 2012 at 8:32 AM, Bryan Berry bryan.berry@gmail.com wrote:

Dear Chefs,

I work on almost basis with the Enterprise Java container known as JBoss AS
7. JBoss's main configuration file, standalone-full.xml, is a whopping 553
lines long. While it is very long, it actually quite cleanly structured,
especially when compared to something like sendmail.cf

Templating such a large file is a mega PITA. JBoss AS 7 is nicely
componentized so that you can easily turn on and off modules. This process
would be a billion times easier and more readable if I could include
fragments within and erubis template like this:

<?xml version='1.0' encoding='UTF-8'?> <% if @infinispan -%> <% end -%> <% if @webservices -%> <% end -%> <% if @infinispan include_template "infinispan.xml.erb" end -%> <% if @webservices include_template "webservices.xml.erb" end -%> ......

As you can see, this is far more readable than adding complex logic to
already large file

Is this at all feasible currently in Chef? It would make life a lot easier
for me

Now that I re-read your email, I see the concept of embedded template
within a template.
That makes it more complex.
I don't know about that one yet.

On Thu, Jun 28, 2012 at 8:39 AM, Mike miketheman@gmail.com wrote:

Hi Bryan,

Here's a segment of a configuration file that uses 'if' statements:
https://github.com/DataDog/cookbooks/blob/master/datadog/templates/default/datadog.conf.erb#L21-53
(Do as I say, not as I do: the node attribute accessors should
probably be strings vs symbols, but that's a future improvement).

My template is referencing directly against node attributes, you may
with to pass variables to the template resource for config items that
aren't exactly node attributes.

More on templates: http://wiki.opscode.com/display/chef/Templates

Best,
-M

On Thu, Jun 28, 2012 at 8:32 AM, Bryan Berry bryan.berry@gmail.com wrote:

Dear Chefs,

I work on almost basis with the Enterprise Java container known as JBoss AS
7. JBoss's main configuration file, standalone-full.xml, is a whopping 553
lines long. While it is very long, it actually quite cleanly structured,
especially when compared to something like sendmail.cf

Templating such a large file is a mega PITA. JBoss AS 7 is nicely
componentized so that you can easily turn on and off modules. This process
would be a billion times easier and more readable if I could include
fragments within and erubis template like this:

<?xml version='1.0' encoding='UTF-8'?> <% if @infinispan -%> <% end -%> <% if @webservices -%> <% end -%> <% if @infinispan include_template "infinispan.xml.erb" end -%> <% if @webservices include_template "webservices.xml.erb" end -%> ......

As you can see, this is far more readable than adding complex logic to
already large file

Is this at all feasible currently in Chef? It would make life a lot easier
for me

"Partials" would be kind of a nice addition to chef ... IMHO

-john

On Jun 28, 2012, at 8:42 AM, Mike miketheman@gmail.com wrote:

Now that I re-read your email, I see the concept of embedded template
within a template.
That makes it more complex.
I don't know about that one yet.

On Thu, Jun 28, 2012 at 8:39 AM, Mike miketheman@gmail.com wrote:

Hi Bryan,

Here's a segment of a configuration file that uses 'if' statements:
https://github.com/DataDog/cookbooks/blob/master/datadog/templates/default/datadog.conf.erb#L21-53
(Do as I say, not as I do: the node attribute accessors should
probably be strings vs symbols, but that's a future improvement).

My template is referencing directly against node attributes, you may
with to pass variables to the template resource for config items that
aren't exactly node attributes.

More on templates: http://wiki.opscode.com/display/chef/Templates

Best,
-M

On Thu, Jun 28, 2012 at 8:32 AM, Bryan Berry bryan.berry@gmail.com wrote:

Dear Chefs,

I work on almost basis with the Enterprise Java container known as JBoss AS
7. JBoss's main configuration file, standalone-full.xml, is a whopping 553
lines long. While it is very long, it actually quite cleanly structured,
especially when compared to something like sendmail.cf

Templating such a large file is a mega PITA. JBoss AS 7 is nicely
componentized so that you can easily turn on and off modules. This process
would be a billion times easier and more readable if I could include
fragments within and erubis template like this:

<?xml version='1.0' encoding='UTF-8'?> <% if @infinispan -%> <% end -%> <% if @webservices -%> <% end -%> <% if @infinispan include_template "infinispan.xml.erb" end -%> <% if @webservices include_template "webservices.xml.erb" end -%> ......

As you can see, this is far more readable than adding complex logic to
already large file

Is this at all feasible currently in Chef? It would make life a lot easier
for me

Not a universal fix, but could you possibly do it at a higher level with
xml:include statements?

Michael
On Jun 28, 2012 8:32 AM, "Bryan Berry" bryan.berry@gmail.com wrote:

Dear Chefs,

I work on almost basis with the Enterprise Java container known as JBoss
AS 7. JBoss's main configuration file, standalone-full.xml, is a whopping
553 lines long. While it is very long, it actually quite cleanly
structured, especially when compared to something like sendmail.cf

Templating such a large file is a mega PITA. JBoss AS 7 is nicely
componentized so that you can easily turn on and off modules. This process
would be a billion times easier and more readable if I could include
fragments within and erubis template like this:

<?xml version='1.0' encoding='UTF-8'?> <% if @infinispan -%> <% end -%> <% if @webservices -%> <% end -%> <% if @infinispan include_template "infinispan.xml.erb" end -%> <% if @webservices include_template "webservices.xml.erb" end -%> ......

As you can see, this is far more readable than adding complex logic to
already large file

Is this at all feasible currently in Chef? It would make life a lot easier
for me

Ah - I think I like that approach better - it's very similar to the
/something.d/ method of inclusion - include something it it is there.

Bryan, thoughts?

On Thu, Jun 28, 2012 at 9:29 AM, Michael Della Bitta
michael.della.bitta@appinions.com wrote:

Not a universal fix, but could you possibly do it at a higher level with
xml:include statements?

Michael

On Jun 28, 2012 8:32 AM, "Bryan Berry" bryan.berry@gmail.com wrote:

Dear Chefs,

I work on almost basis with the Enterprise Java container known as JBoss
AS 7. JBoss's main configuration file, standalone-full.xml, is a whopping
553 lines long. While it is very long, it actually quite cleanly structured,
especially when compared to something like sendmail.cf

Templating such a large file is a mega PITA. JBoss AS 7 is nicely
componentized so that you can easily turn on and off modules. This process
would be a billion times easier and more readable if I could include
fragments within and erubis template like this:

<?xml version='1.0' encoding='UTF-8'?> <% if @infinispan -%> <% end -%> <% if @webservices -%> <% end -%> <% if @infinispan include_template "infinispan.xml.erb" end -%> <% if @webservices include_template "webservices.xml.erb" end -%> ......

As you can see, this is far more readable than adding complex logic to
already large file

Is this at all feasible currently in Chef? It would make life a lot easier
for me

Mikes,

afaict, it won't work if you have any ruby in the included templates. You
could get aroung that by having a template resource in your main recipe for
each included "template" but I think that is unnecessary verbosity.

Also, I have no idea how well different EJB containers handle the
xml:include statement. Perhaps there are gotchas there that I am not
aware of. Also, it's something I would rather not become an expert on :stuck_out_tongue:

On Thu, Jun 28, 2012 at 4:12 PM, Mike miketheman@gmail.com wrote:

Ah - I think I like that approach better - it's very similar to the
/something.d/ method of inclusion - include something it it is there.

Bryan, thoughts?

On Thu, Jun 28, 2012 at 9:29 AM, Michael Della Bitta
michael.della.bitta@appinions.com wrote:

Not a universal fix, but could you possibly do it at a higher level with
xml:include statements?

Michael

On Jun 28, 2012 8:32 AM, "Bryan Berry" bryan.berry@gmail.com wrote:

Dear Chefs,

I work on almost basis with the Enterprise Java container known as JBoss
AS 7. JBoss's main configuration file, standalone-full.xml, is a
whopping
553 lines long. While it is very long, it actually quite cleanly
structured,
especially when compared to something like sendmail.cf

Templating such a large file is a mega PITA. JBoss AS 7 is nicely
componentized so that you can easily turn on and off modules. This
process
would be a billion times easier and more readable if I could include
fragments within and erubis template like this:

<?xml version='1.0' encoding='UTF-8'?> <% if @infinispan -%> <% end -%> <% if @webservices -%> <% end -%> <% if @infinispan include_template "infinispan.xml.erb" end -%> <% if @webservices include_template "webservices.xml.erb" end -%> ......

As you can see, this is far more readable than adding complex logic to
already large file

Is this at all feasible currently in Chef? It would make life a lot
easier
for me

+1 for partials. It will make handling config files for those tools which
does not have a include dir=/etc/xxx/*.cfg , lot simpler.

On Thu, Jun 28, 2012 at 8:55 PM, John Dyer johntdyer@gmail.com wrote:

"Partials" would be kind of a nice addition to chef ... IMHO

-john

On Jun 28, 2012, at 8:42 AM, Mike miketheman@gmail.com wrote:

Now that I re-read your email, I see the concept of embedded template
within a template.
That makes it more complex.
I don't know about that one yet.

On Thu, Jun 28, 2012 at 8:39 AM, Mike miketheman@gmail.com wrote:

Hi Bryan,

Here's a segment of a configuration file that uses 'if' statements:

https://github.com/DataDog/cookbooks/blob/master/datadog/templates/default/datadog.conf.erb#L21-53

(Do as I say, not as I do: the node attribute accessors should
probably be strings vs symbols, but that's a future improvement).

My template is referencing directly against node attributes, you may
with to pass variables to the template resource for config items that
aren't exactly node attributes.

More on templates: http://wiki.opscode.com/display/chef/Templates

Best,
-M

On Thu, Jun 28, 2012 at 8:32 AM, Bryan Berry bryan.berry@gmail.com
wrote:

Dear Chefs,

I work on almost basis with the Enterprise Java container known as
JBoss AS
7. JBoss's main configuration file, standalone-full.xml, is a
whopping 553
lines long. While it is very long, it actually quite cleanly
structured,
especially when compared to something like sendmail.cf

Templating such a large file is a mega PITA. JBoss AS 7 is nicely
componentized so that you can easily turn on and off modules. This
process
would be a billion times easier and more readable if I could include
fragments within and erubis template like this:

<?xml version='1.0' encoding='UTF-8'?> <% if @infinispan -%> <% end -%> <% if @webservices -%> <% end -%> <% if @infinispan include_template "infinispan.xml.erb" end -%> <% if @webservices include_template "webservices.xml.erb" end -%> ......

As you can see, this is far more readable than adding complex logic to
already large file

Is this at all feasible currently in Chef? It would make life a lot
easier
for me

Yes, I like this!!

From: Bryan Berry [mailto:bryan.berry@gmail.com]
Sent: Thursday, June 28, 2012 5:32 AM
To: chef@lists.opscode.com
Subject: [chef] including erubis fragments within a template

Dear Chefs,

I work on almost basis with the Enterprise Java container known as JBoss
AS 7. JBoss’s main configuration file, standalone-full.xml, is a
whopping 553 lines long. While it is very long, it actually quite
cleanly structured, especially when compared to something like
sendmail.cf

Templating such a large file is a mega PITA. JBoss AS 7 is nicely
componentized so that you can easily turn on and off modules. This
process would be a billion times easier and more readable if I could
include fragments within and erubis template like this:

<?xml version='1.0' encoding='UTF-8'?>
<extensions>

     <% if @infinispan -%>

    <extension module="org.jboss.as.clustering.infinispan"/>

    <% end -%>

    <extension module="org.jboss.as.web"/>

     <% if @webservices -%>

    <extension module="org.jboss.as.webservices"/>

    <% end -%>

    <extension module="org.jboss.as.weld"/>

</extensions>

 <% if @infinispan 

           include_template "infinispan.xml.erb"

 end -%>

 <% if @webservices

           include_template "webservices.xml.erb"

 end -%>
......

As you can see, this is far more readable than adding complex logic to
already large file

Is this at all feasible currently in Chef? It would make life a lot
easier for me

Brian,

I went ahead and opened this on your behalf (
http://tickets.opscode.com/browse/CHEF-3249 ). Anyone thats interested
should upvote it to make sure it gets some attention.

Thanks!

-John

On Thu, Jun 28, 2012 at 8:32 AM, Bryan Berry bryan.berry@gmail.com wrote:

Dear Chefs,

I work on almost basis with the Enterprise Java container known as JBoss
AS 7. JBoss's main configuration file, standalone-full.xml, is a whopping
553 lines long. While it is very long, it actually quite cleanly
structured, especially when compared to something like sendmail.cf

Templating such a large file is a mega PITA. JBoss AS 7 is nicely
componentized so that you can easily turn on and off modules. This process
would be a billion times easier and more readable if I could include
fragments within and erubis template like this:

<?xml version='1.0' encoding='UTF-8'?> <% if @infinispan -%> <% end -%> <% if @webservices -%> <% end -%> <% if @infinispan include_template "infinispan.xml.erb" end -%> <% if @webservices include_template "webservices.xml.erb" end -%> ......

As you can see, this is far more readable than adding complex logic to
already large file

Is this at all feasible currently in Chef? It would make life a lot easier
for me

Errr, Bryan, sorry :slight_smile:

On Thu, Jun 28, 2012 at 2:33 PM, John Dyer johntdyer@gmail.com wrote:

Brian,

I went ahead and opened this on your behalf (
http://tickets.opscode.com/browse/CHEF-3249 ). Anyone thats interested
should upvote it to make sure it gets some attention.

Thanks!

-John

On Thu, Jun 28, 2012 at 8:32 AM, Bryan Berry bryan.berry@gmail.comwrote:

Dear Chefs,

I work on almost basis with the Enterprise Java container known as JBoss
AS 7. JBoss's main configuration file, standalone-full.xml, is a whopping
553 lines long. While it is very long, it actually quite cleanly
structured, especially when compared to something like sendmail.cf

Templating such a large file is a mega PITA. JBoss AS 7 is nicely
componentized so that you can easily turn on and off modules. This process
would be a billion times easier and more readable if I could include
fragments within and erubis template like this:

<?xml version='1.0' encoding='UTF-8'?> <% if @infinispan -%> <% end -%> <% if @webservices -%> <% end -%> <% if @infinispan include_template "infinispan.xml.erb" end -%> <% if @webservices include_template "webservices.xml.erb" end -%> ......

As you can see, this is far more readable than adding complex logic to
already large file

Is this at all feasible currently in Chef? It would make life a lot
easier for me

Tks j0Hn!
On Jun 28, 2012 8:34 PM, "John Dyer" johntdyer@gmail.com wrote:

Errr, Bryan, sorry :slight_smile:

On Thu, Jun 28, 2012 at 2:33 PM, John Dyer johntdyer@gmail.com wrote:

Brian,

I went ahead and opened this on your behalf (
http://tickets.opscode.com/browse/CHEF-3249 ). Anyone thats interested
should upvote it to make sure it gets some attention.

Thanks!

-John

On Thu, Jun 28, 2012 at 8:32 AM, Bryan Berry bryan.berry@gmail.comwrote:

Dear Chefs,

I work on almost basis with the Enterprise Java container known as JBoss
AS 7. JBoss's main configuration file, standalone-full.xml, is a whopping
553 lines long. While it is very long, it actually quite cleanly
structured, especially when compared to something like sendmail.cf

Templating such a large file is a mega PITA. JBoss AS 7 is nicely
componentized so that you can easily turn on and off modules. This process
would be a billion times easier and more readable if I could include
fragments within and erubis template like this:

<?xml version='1.0' encoding='UTF-8'?> <% if @infinispan -%> <% end -%> <% if @webservices -%> <% end -%> <% if @infinispan include_template "infinispan.xml.erb" end -%> <% if @webservices include_template "webservices.xml.erb" end -%> ......

As you can see, this is far more readable than adding complex logic to
already large file

Is this at all feasible currently in Chef? It would make life a lot
easier for me