Information Technology Reference
In-Depth Information
$ chef generate template custom
Chef Client - Linux/Mac OS X:
$ touch templates/default/custom.erb
Chef Client - Windows:
$ touch templates\default\custom.erb
Create templates/default/custom.erb as shown in Example 15-10 . We're using this optional
apache configuration file to set the port the server is listening on via the Listen setting and
the DocumentRoot .
We will explain the if syntax in the template in more detail in Chapter 16 . In short for now,
you can place conditional logic in templates when it is enclosed by <% %> (vs. <%= %> when
you want to evaluate a string). Also, if the closing tag has a minus sign in it, such as -%> , the
line is removed from the resultant template output when it is evaluated. Therefore, in
Example 15-10 , these three lines are processed when the template file is evaluated: <% if
@port != 80 -%> , Listen <%= @port %> , and <% end -%> . When the evaluated output is
written to the resultant template file, it becomes just one line, because there are -%> symbols
on the first and the third lines: Listen <%= @port %> . Further, the single line with Listen
<%= @port %> is only written to the resultant template file if the conditional logic evaluates
to a port number besides 80.
We need this conditional logic in the template because the Listen line is required in the
.conf file when any port besides 80 is used. If we left out the conditional, we'd get an error
configuring the website if it evaluates to port 80 .
Example 15-10. chefdk/chef-zero/apache/templates/default/custom.erb
< % if @port != 80 -%>
Listen < %= @port %>
< % end -%>
<VirtualHost
<VirtualHost * : <%= @ port % > >
ServerAdmin webmaster@localhost
DocumentRoot < %= @document_root %>
<Directory
<Directory //>
 
 
 
Search WWH ::




Custom Search