Cookbook Recipe : 8

 

Example8: Installing Package httpd, server enable, service start, on Node.

[root@chef-workstation cookbooks]# chef generate cookbook httpd
Generating cookbook httpd
- Ensuring correct cookbook content
- Committing cookbook files to git

Your cookbook is ready. Type `cd httpd` to enter it.

There are several commands you can run to get started locally developing and testing your cookbook.

Why not start by writing an InSpec test? Tests for the default recipe are stored at:

test/integration/default/default_test.rb

If you'd prefer to dive right in, the default recipe can be found at:

recipes/default.rb

[root@chef-workstation cookbooks]# cd httpd/recipes/
[root@chef-workstation recipes]# vi default.rb
[root@chef-workstation recipes]# cat default.rb
#
# Cookbook:: httpd
# Recipe:: default
#
# Copyright:: 2022, The Authors, All Rights Reserved.

package "httpd" do
action :install
end

service "httpd" do
action :start
end

service "httpd" do
action :enable
end

#service "httpd" do
#action [:start,:enable]
#end

file "/sai/chef1.html" do
action :create
content "Hi Friends, How are you?"
end
[root@chef-workstation recipes]#
[root@chef-workstation recipes]#
[root@chef-workstation recipes]#  knife cookbook upload httpd
Uploading httpd          [0.1.0]
Uploaded 1 cookbook.
[root@chef-workstation recipes]# 
[root@chef-workstation recipes]# knife node run_list add Node-1 "recipe[httpd]"
Node-1:
  run_list:
    recipe[httpd]
[root@chef-workstation recipes]# 
[root@chef-workstation recipes]# knife node show Node-1
Node Name:   Node-1
Environment: _default
FQDN:        node1
IP:          192.168.2.133
Run List:    recipe[httpd]
Roles:
Recipes:     git, git::default
Platform:    centos 7.9.2009
Tags:
[root@chef-workstation recipes]#

Node1: 



----------------------------End of Example8---------------------------------------

Cookbook Recipe : 9


Comments

Popular posts from this blog

To change the data directory location for PostgreSQL after installation

AWR

GIT