+91 700 483 5930   +91 810 584 3520    info@scmgalaxy.com
LOGIN
Sign In or Register
Avatar
Not Registered Yet?

Join Now! It's FREE. Get full access and benefit from this site

Reset My password - Remind Me My username

Username
Password
Remember me
 
scmGalaxy logo

What is the significance of the default directory under chef cookbook /templates?

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

Reference
https://docs.chef.io/resource_template.html
Rate this item
(3 votes)
Rajesh Kumar

.

Total, Over 12 years of extensive experience in the Software Configuration Management domain having depth knowledge of DevOps, Continuous Integration and Delivery, Configuration Management, Build and Installer, Release Management and Application Management.

NEW TUTORIALS