Use partial templates to create configuration files
The templates for configuration files for each of the services have parts that are (for the most part) the same as all of the other services. The biggest part of commonality is the MQ configurations. These common parts can be put in a common partial template that is used by all of the projects.
Updated by zhiwei at 20150-04-20
There are some common section/options in the configuration file of all the OpenStack projects, we can put the same section/options in one Chef partial templates and reference it in all cookbooks.
We should use attribute direct access in templates, no variables, this will also allow users easy to update the configuration file through attributes in Chef environment file.
I will take database section as an example, the changes are:
1. In openstack-common cookbooks:
* Add a partial template file `templates/
[database]
backend=<%= node['openstack
connection=<%= node['openstack
* Update database attribute file like:
%w(identity compute ...).each do |project|
default[
db_user = ...
db_pass = get_password('db', project)
default[
end
2. In openstack-project cookbooks:
* In recipes, add a template resource like:
template '/etc/project/
source 'project.conf.erb'
variables(
project: 'project_name',
partials: {
'
}
)
end
* In templates, add something like:
<% @partials.each do |partial, cookbook| %>
<%= render partial, :cookbook => cookbook %>
<% end %>
Blueprint information
- Status:
- Complete
- Approver:
- JJ Asghar
- Priority:
- Low
- Drafter:
- Ryan Rossiter
- Direction:
- Needs approval
- Assignee:
- None
- Definition:
- Obsolete
- Series goal:
- Accepted for kilo
- Implementation:
- Not started
- Milestone target:
- None
- Started by
- Completed by
- JJ Asghar
Whiteboard
Partial Templates
A template can be built in a way that allows it to contain references to one (or more) smaller template files. (These smaller template files are also referred to as partials.) A partial can be referenced from a template file in one of the following ways:
By using the Ruby render method in the template file
By using the template resource and the variables parameter.
render Method
Use the render method in a template to reference a partial template file:
<%= render "partial_
where partial_name is the name of the partial template file and :option is one (or more) of the following:
Option Description
:cookbook By default, a partial template file is assumed to be located in the cookbook that contains the top-level template. Use this option to specify the path to a different cookbook
:local Indicates that the name of the partial template file should be interpreted as a path to a file in the local file system or looked up in a cookbook using the normal rules for template files. Set to true to interpret as a path to a file in the local file system and to false to use the normal rules for template files
:source By default, a partial template file is identified by its file name. Use this option to specify a different name or a local path to use (instead of the name of the partial template file)
:variables A hash of variable_name => value that will be made available to the partial template file. When this option is used, any variables that are defined in the top-level template that are required by the partial template file must have them defined explicitly using this option
For example:
<%= render "simple.txt.erb", :variables => {:user => Etc.getlogin }, :local => true %>
Gerrit topic: https:/
Addressed by: https:/
Use partial templates to create configuration files