{"id":671,"date":"2017-07-26T06:39:53","date_gmt":"2017-07-26T06:39:53","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2017\/07\/26\/what-is-the-significance-of-the-default-directory-under-chef-cookbook-templates\/"},"modified":"2021-11-19T05:56:36","modified_gmt":"2021-11-19T05:56:36","slug":"what-is-the-significance-of-the-default-directory-under-chef-cookbook-templates","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/what-is-the-significance-of-the-default-directory-under-chef-cookbook-templates\/","title":{"rendered":"What is the significance of the default directory under chef cookbook \/templates?"},"content":{"rendered":"<div><\/div>\n<div>What is the significance of the default directory under chef cookbook \/templates?<\/div>\n<div><\/div>\n<div>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.<\/div>\n<div><\/div>\n<div><strong>The pattern for template specificity depends on two things: the lookup path and the source. The first pattern that matches is used:<\/strong><\/div>\n<div><\/div>\n<div>\/host-$fqdn\/$source<\/div>\n<div>\/$platform-$platform_version\/$source<\/div>\n<div>\/$platform\/$source<\/div>\n<div>\/default\/$source<\/div>\n<div>\/$source<\/div>\n<div><\/div>\n<div><strong>Use an array with the source property to define an explicit lookup path. For example:<\/strong><\/div>\n<div>template &#8216;\/test&#8217; do<\/div>\n<div>&nbsp; source [&#8220;#{node.chef_environment}.erb&#8221;, &#8216;default.erb&#8217;]<\/div>\n<div>end<\/div>\n<div><\/div>\n<div><strong>The following example emulates the entire file specificity pattern by defining it as an explicit path:<\/strong><\/div>\n<div>template &#8216;\/test&#8217; do<\/div>\n<div>&nbsp; source %W{<\/div>\n<div>&nbsp; &nbsp; host-#{node[&#8216;fqdn&#8217;]}\/test.erb<\/div>\n<div>&nbsp; &nbsp; #{node[&#8216;platform&#8217;]}-#{node[&#8216;platform_version&#8217;]}\/test.erb<\/div>\n<div>&nbsp; &nbsp; #{node[&#8216;platform&#8217;]}\/test.erb<\/div>\n<div>&nbsp; &nbsp; default\/test.erb<\/div>\n<div>&nbsp; }<\/div>\n<div>end<\/div>\n<div><\/div>\n<div><strong>A cookbook may have a \/templates directory structure like this:<\/strong><\/div>\n<div>\/templates\/<\/div>\n<div>&nbsp; windows-6.2<\/div>\n<div>&nbsp; windows-6.1<\/div>\n<div>&nbsp; windows-6.0<\/div>\n<div>&nbsp; windows<\/div>\n<div>&nbsp; default<\/div>\n<div><\/div>\n<div><strong>and a resource that looks something like the following:<\/strong><\/div>\n<div>template &#8216;C:\\path\\to\\file\\text_file.txt&#8217; do<\/div>\n<div>&nbsp; source &#8216;text_file.txt&#8217;<\/div>\n<div>&nbsp; mode &#8216;0755&#8217;<\/div>\n<div>&nbsp; owner &#8216;root&#8217;<\/div>\n<div>&nbsp; group &#8216;root&#8217;<\/div>\n<div>end<\/div>\n<div><\/div>\n<div><strong>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:<\/strong><\/div>\n<div>\/templates<\/div>\n<div>&nbsp; windows-6.2\/text_file.txt<\/div>\n<div>&nbsp; windows-6.1\/text_file.txt<\/div>\n<div>&nbsp; windows-6.0\/text_file.txt<\/div>\n<div>&nbsp; windows\/text_file.txt<\/div>\n<div>\n<p>&nbsp; default\/text_file.txt<\/p>\n<p><strong>Reference<\/strong><br>\n<a href=\"https:\/\/docs.chef.io\/resource_template.html\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/docs.chef.io\/resource_template.html<\/a><\/p>\n<\/div>\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_10348\"><figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube epyt-figure\"><div class=\"wp-block-embed__wrapper\"><iframe loading=\"lazy\"  id=\"_ytid_77955\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_10348\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":1,"featured_media":2878,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[88],"tags":[407,636,642,604,643,602,644],"class_list":["post-671","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chef","tag-chef","tag-chef-client","tag-chef-cookbook","tag-chef-guide","tag-chef-templates","tag-chef-tutorials","tag-default-directory"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/671","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=671"}],"version-history":[{"count":6,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/671\/revisions"}],"predecessor-version":[{"id":25760,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/671\/revisions\/25760"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/2878"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=671"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=671"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=671"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}