What is the significance of the default directory under chef cookbook /templates?
A cookbook is frequently designed to work across many platforms and is often required to distribute a specific template to a specific platform. This is a New in Chef Client 12.0. A cookbook can be designed to support the distribution of templates across platforms, while ensuring that the correct template ends up on each system.
The pattern for template specificity depends on two things: the lookup path and the source. The first pattern that matches is used:
/host-$fqdn/$source
/$platform-$platform_version/$source
/$platform/$source
/default/$source
/$source
Use an array with the source property to define an explicit lookup path. For example:
template ‘/test’ do
source [“#{node.chef_environment}.erb”, ‘default.erb’]
end
The following example emulates the entire file specificity pattern by defining it as an explicit path:
template ‘/test’ do
source %W{
host-#{node[‘fqdn’]}/test.erb
#{node[‘platform’]}-#{node[‘platform_version’]}/test.erb
#{node[‘platform’]}/test.erb
default/test.erb
}
end
A cookbook may have a /templates directory structure like this:
/templates/
windows-6.2
windows-6.1
windows-6.0
windows
default
and a resource that looks something like the following:
template ‘C:\path\to\file\text_file.txt’ do
source ‘text_file.txt’
mode ‘0755’
owner ‘root’
group ‘root’
end
This resource would be matched in the same order as the /templates directory structure. For a node named host-node-desktop that is running Windows 7, the second item would be the matching item and the location:
/templates
windows-6.2/text_file.txt
windows-6.1/text_file.txt
windows-6.0/text_file.txt
windows/text_file.txt
default/text_file.txt
Chef Essential Tutorial By Rajesh Kumar in 2020 – Session-1
Chef Essential Tutorial By Rajesh Kumar in 2020 – Session-2
Chef Essential Tutorial By Rajesh Kumar in 2020 – Session-3
Latest posts by Rajesh Kumar (see all)
- Best AI tools for Software Engineers - November 4, 2024
- Installing Jupyter: Get up and running on your computer - November 2, 2024
- An Introduction of SymOps by SymOps.com - October 30, 2024