{"id":31859,"date":"2022-11-22T10:42:26","date_gmt":"2022-11-22T10:42:26","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=31859"},"modified":"2022-12-23T05:45:27","modified_gmt":"2022-12-23T05:45:27","slug":"chef-tutorials-template-resource-with-example","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/chef-tutorials-template-resource-with-example\/","title":{"rendered":"Chef Tutorials: template Resource with example"},"content":{"rendered":"\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>What is cookbook template (.erb)<\/strong><\/p>\n\n\n\n<p>A cookbook template is an Embedded Ruby (ERB) template that is used to dynamically generate static text files. Templates may contain Ruby expressions and statements, and are a great way to manage configuration files.<\/p>\n\n\n\n<p>Use the template resource to add cookbook templates to recipes; place the corresponding Embedded Ruby (ERB) template file in a cookbook\u2019s \/templates directory. template resource would not work with chef-apply but can be used with chef-solo.<\/p>\n\n\n\n<p>Use the template resource to manage the contents of a file using an Embedded Ruby (ERB) template by transferring files from a sub-directory of COOKBOOK_NAME\/templates\/ to a specified path located on a host that is running Chef Infra Client.<\/p>\n\n\n\n<p><strong>ERB Specification<\/strong><\/p>\n\n\n\n<p>Chef uses Erubis as its template language. It allows embedding pure Ruby code inside special symbols in the templates.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"93\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/11\/image-23-1024x93.png\" alt=\"\" class=\"wp-image-31860\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/11\/image-23-1024x93.png 1024w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/11\/image-23-300x27.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/11\/image-23-768x70.png 768w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/11\/image-23-1536x140.png 1536w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/11\/image-23.png 1792w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<script src=\"https:\/\/gist.github.com\/devops-school\/56f994e6e6f989bda42fc403edb7472f.js\"><\/script>\n\n\n\n<h2 class=\"wp-block-heading\">Reference<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>https:\/\/docs.chef.io\/templates\/<\/li>\n\n\n\n<li>https:\/\/github.com\/scmgalaxy\/chef-repo<\/li>\n\n\n\n<li>https:\/\/docs.chef.io\/resources\/template\/<\/li>\n\n\n\n<li>https:\/\/docs.aws.amazon.com\/opsworks\/latest\/userguide\/cookbooks-101-basics-attributes.html<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>What is cookbook template (.erb) A cookbook template is an Embedded Ruby (ERB) template that is used to dynamically generate static text files. Templates may contain Ruby expressions and statements, and are a great way to manage configuration files. Use the template resource to add cookbook templates to recipes; place the corresponding Embedded Ruby (ERB)&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","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":[2],"tags":[],"class_list":["post-31859","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/31859","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=31859"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/31859\/revisions"}],"predecessor-version":[{"id":31862,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/31859\/revisions\/31862"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=31859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=31859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=31859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}