Separate config template to partial template

Registered by zhiwei

Source: https://blueprints.launchpad.net/openstack-chef/+spec/conf-partial-templates

Should mark this blueprint as duplicated.

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/default/database.erb`, content like:

[database]
backend=<%= node['openstack']['db'][@project]['backend']%>
connection=<%= node['openstack']['db'][@project]['connection'] %>

* Update database attribute file like:

%w(identity compute ...).each do |project|
  default['openstack']['db'][project]['backend'] = 'sqlalchemy'
  db_user = ...
  db_pass = get_password('db', project)
  default['openstack']['db'][project][connection] = db_uri(project, db_user, db_pass)
end

2. In openstack-project cookbooks:

* In recipes, add a template resource like:

template '/etc/project/project.conf' do
  source 'project.conf.erb'
  variables(
    project: 'project_name',
    partials: {
      'database.erb' => 'openstack-common'
    }
  )
end

* In templates, add something like:

<% @partials.each do |partial, cookbook| %>
<%= render partial, :cookbook => cookbook %>
<% end %>

Blueprint information

Status:
Complete
Approver:
None
Priority:
Undefined
Drafter:
zhiwei
Direction:
Needs approval
Assignee:
None
Definition:
Obsolete
Series goal:
None
Implementation:
Unknown
Milestone target:
None
Completed by
zhiwei

Related branches

Sprints

Whiteboard

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.