{"id":431,"date":"2015-09-20T09:17:05","date_gmt":"2015-09-20T09:17:05","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2015\/09\/20\/chef-commands-line-reference\/"},"modified":"2021-11-19T06:59:01","modified_gmt":"2021-11-19T06:59:01","slug":"chef-commands-line-reference","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/chef-commands-line-reference\/","title":{"rendered":"Chef frequently used commands collection"},"content":{"rendered":"<p><strong>To run single recipe using chef-solo<\/strong><\/p>\n<pre><code>&gt; chef-solo -c \/opt\/chef\/repo\/config\/solo.rb -o my_cookbook::recipe<\/code><\/pre>\n<p><strong>To run the single reciepe in same machine<\/strong><\/p>\n<p>&gt; chef-apply hello.rb<\/p>\n<p><strong>To generate the cookbook standard structure<\/strong><\/p>\n<pre>&gt; chef generate cookbook learn_chef_httpd<\/pre>\n<pre>&gt; knife cookbook create smartmontools -r md<\/pre>\n<p><strong>To generate the template file in cookbook<\/strong><\/p>\n<pre>&gt; chef generate template learn_chef_httpd index.html<\/pre>\n<p><strong>To run the cookbook in local mode<\/strong><\/p>\n<pre>&gt; sudo chef-client --local-mode --runlist \u2018recipe[learn_chef_httpd]\u2019<\/pre>\n<pre><\/pre>\n<p><strong>To download the cookbooks from market place<\/strong><\/p>\n<pre>&gt; knife cookbook site download learn_chef_httpd<\/pre>\n<pre>&gt; knife cookbook site install learn_chef_httpd<\/pre>\n<pre><\/pre>\n<p><strong>To Upload the cookbooks to chef server<\/strong><\/p>\n<pre>&gt; knife cookbook upload learn_chef_httpd<\/pre>\n<pre>&gt; knife cookbook upload -a<\/pre>\n<p><strong>To bootstrap a nodes<\/strong><\/p>\n<pre>&gt; knife bootstrap {{address}} --ssh-user {{user}} --ssh-password '{{password}}' --sudo --use-sudo-password --node-name node1 --run-list 'recipe[learn_chef_apache2]'<\/pre>\n<pre>&gt; knife bootstrap uvo1t75faaktzc532w6.vm.cld.sr -x root -P Br356YS0iy \u2013sudo \u2013node-name firefox<\/pre>\n<pre>&gt; knife bootstrap 123.45.6.789 -x username -P password \u2013sudo<\/pre>\n<pre><\/pre>\n<p><strong>To see the list of nodes<\/strong><\/p>\n<pre>&gt;knife node list<\/pre>\n<p><strong>To edit the node run list<\/strong><\/p>\n<pre>&gt; knife node edit name_of_node<\/pre>\n<p><strong>To see the info about each nodes<\/strong><\/p>\n<pre>&gt; knife node show node1<\/pre>\n<p><strong>Run the cooksbooks on nodes<\/strong><\/p>\n<pre>&gt; knife ssh {{address}} 'sudo chef-client' --manual-list --ssh-user {{user}} --ssh-password '{{password}}'<\/pre>\n<pre>&gt; ssh username@ipadddress -i mycredentials.pem sudo chef-client<\/pre>\n<p><strong>To add the run list to the nodes.<\/strong><\/p>\n<pre>knife node run_list add C2445575914.domain 'recipe[hptrain]'<\/pre>\n<pre>knife node run_list set test-node '''recipe[iptables]''' [Windows - Powershell]<\/pre>\n<pre>knife node run_list set test-node 'recipe[iptables]' [Windows - Command]<\/pre>\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_52658\"><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_16204\"  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_52658\"  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>To run single recipe using chef-solo &gt; chef-solo -c \/opt\/chef\/repo\/config\/solo.rb -o my_cookbook::recipe To run the single reciepe in same machine &gt; chef-apply hello.rb To generate the cookbook standard structure &gt; chef generate cookbook learn_chef_httpd &gt; knife cookbook create smartmontools -r md To generate the template file in cookbook &gt; chef generate template learn_chef_httpd index.html To&#8230;<\/p>\n","protected":false},"author":1,"featured_media":3356,"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":[1385,407,1493,1495,1488,1491,1492,1489,1490,1494,1496,333,824],"class_list":["post-431","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chef","tag-cheatsheet","tag-chef","tag-chef-commands","tag-chef-commands-guide","tag-chef-commands-line","tag-chef-commands-line-guide","tag-chef-commands-line-help","tag-chef-commands-line-reference","tag-chef-commands-line-tutorial","tag-chef-commands-reference","tag-chef-commands-tutorials","tag-command","tag-command-line"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/431","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=431"}],"version-history":[{"count":4,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/431\/revisions"}],"predecessor-version":[{"id":25808,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/431\/revisions\/25808"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/3356"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}