Chef-apply and receipe syntax
From Notes_Wiki
<yambe:breadcrumb>Chef|Chef</yambe:breadcrumb>
chef-apply and receipe syntax
Using chef to work with a resource
- Download chef development kit from https://downloads.chef.io/chef-dk/
- Install chef-development kit using rpm
- Create file hello.rb with following contents
- file 'motd' do
- content 'hello world'
- end
- Run 'chef-apply hello.rb'
- Update hello.rb to
- file 'motd' do
- action :delete
- end
- 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
- Create folder ~/cookbooks and cd to it.
- Create cookbook using 'chef generate cookbook learn_chef_httpd'
- Create template in new cookbook using:
- chef generate template learn_chef_httpd index.html
- 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
- chef-client --local-mode --runlist 'recipe[learn_chef_httpd]'
Steps learned from https://learn.chef.io/rhel/make-your-recipe-more-manageable/
<yambe:breadcrumb>Chef|Chef</yambe:breadcrumb>