{"id":31864,"date":"2022-11-24T03:30:47","date_gmt":"2022-11-24T03:30:47","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=31864"},"modified":"2022-12-23T05:45:27","modified_gmt":"2022-12-23T05:45:27","slug":"chef-tutorials-how-to-set-conditions-in-chef-cookbooks-recipe-using-guard","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/chef-tutorials-how-to-set-conditions-in-chef-cookbooks-recipe-using-guard\/","title":{"rendered":"Chef Tutorials: How to set Conditions in Chef Cookbooks recipe using Guard?"},"content":{"rendered":"\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Guards<\/h2>\n\n\n\n<p>A guard property can be used to evaluate the state of a node during the execution phase of a Chef Infra Client run. Based on the results of this evaluation, a guard property is then used to tell Chef Infra Client if it should continue executing a resource. A guard property accepts either a string value or a Ruby block value:<\/p>\n\n\n\n<p>A string is executed as a shell command. If the command returns 0, the guard is applied. If the command returns any other value, then the guard property is not applied.<\/p>\n\n\n\n<p>String guards in a powershell_script run Windows PowerShell commands and may return true in addition to 0.<\/p>\n\n\n\n<p>A block is executed as Ruby code that must return either true or false. If the block returns true, the guard property is applied. If the block returns false, the guard property is not applied.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"904\" height=\"652\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/11\/image-24.png\" alt=\"\" class=\"wp-image-31865\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/11\/image-24.png 904w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/11\/image-24-300x216.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/11\/image-24-768x554.png 768w\" sizes=\"auto, (max-width: 904px) 100vw, 904px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"799\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/11\/image-25.png\" alt=\"\" class=\"wp-image-31866\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/11\/image-25.png 709w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/11\/image-25-266x300.png 266w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/devops-school\/50a1b90ba5e423a21479b25cee141a93.js\"><\/script>\n","protected":false},"excerpt":{"rendered":"<p>Guards A guard property can be used to evaluate the state of a node during the execution phase of a Chef Infra Client run. Based on the results of this evaluation, a guard property is then used to tell Chef Infra Client if it should continue executing a resource. A guard property accepts either a&#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-31864","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/31864","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=31864"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/31864\/revisions"}],"predecessor-version":[{"id":31867,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/31864\/revisions\/31867"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=31864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=31864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=31864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}