Chef-apply and receipe syntax

From Notes_Wiki
Revision as of 12:09, 28 July 2022 by Saurabh (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Home > CentOS > CentOS 6.x > System administration tools > chef > Chef-apply and receipe syntax

Using chef to work with a resource

  1. Download chef development kit from https://downloads.chef.io/chef-dk/
  2. Install chef-development kit using rpm
  3. Create file hello.rb with following contents
    file 'motd' do
    content 'hello world'
    end
  4. Run 'chef-apply hello.rb'
  5. Update hello.rb to
    file 'motd' do
    action :delete
    end
  6. Again run 'chef-apply hello.rb'

Read more about 'file' resource at https://docs.chef.io/resource_file.html or http://docs.chef.io/chef/resources.html#file

Other resources such as service and package can be learned using http://docs.chef.io/chef/resources.html#service and http://docs.chef.io/chef/resources.html#package

Steps learned from https://learn.chef.io/rhel/configure-a-resource/ and subsequent chapters



Chef cookbook basics

  1. Create folder ~/cookbooks and cd to it.
  2. Create cookbook using 'chef generate cookbook learn_chef_httpd'
  3. Create template in new cookbook using:
    chef generate template learn_chef_httpd index.html
  4. Update learn_chef_httpd/recipes/default.rb with following
    package 'httpd'
    service 'httpd' do
    action [:start, :enable]
    end
    template '/var/www/html/index.html' do
    source 'index.html.erb'
    end
    service 'iptables' do
    action :stop
    end
  5. chef-client --local-mode --runlist 'recipe[learn_chef_httpd]'


Steps learned from https://learn.chef.io/rhel/make-your-recipe-more-manageable/


Home > CentOS > CentOS 6.x > System administration tools > chef > Chef-apply and receipe syntax