Cookbook Recipe : 7

 

Example7: Installing Package on Node.


package "git" do
action :remove
end


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

Your cookbook is ready. Type `cd git` 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]# ls
chefignore  cookbook1  cookbook2  git  starter
[root@chef-workstation cookbooks]# cd git/recipes
[root@chef-workstation recipes]# vi default.rb
[root@chef-workstation recipes]# cat default.rb
#
# Cookbook:: git
# Recipe:: default
#
# Copyright:: 2022, The Authors, All Rights Reserved.

package "git" do
action :install
end

[root@chef-workstation recipes]#
[root@chef-workstation recipes]# knife cookbook upload git
Uploading git            [0.1.0]
Uploaded 1 cookbook.
[root@chef-workstation recipes]# knife node run_list add Node-1 "recipe[git]"
Node-1:
  run_list:
    recipe[cookbook1]
    recipe[cookbook2]
    recipe[cookbook3]
    recipe[git]
[root@chef-workstation recipes]# 

Node1: 

[root@node1 chef]# chef-client
Chef Infra Client, version 17.10.3
Patents: https://www.chef.io/patents
Infra Phase starting
Resolving cookbooks for run list: ["git"]
Synchronizing cookbooks:
  - git (0.1.0)
Installing cookbook gem dependencies:
Compiling cookbooks...
Loading Chef InSpec profile files:
Loading Chef InSpec input files:
Loading Chef InSpec waiver files:
Converging 1 resources
Recipe: git::default
  * yum_package[git] action install
    - install version 0:1.8.3.1-23.el7_8.x86_64 of package git

Running handlers:
Running handlers complete
Infra Phase complete, 1/1 resources updated in 37 seconds
You have new mail in /var/spool/mail/root
[root@node1 chef]#

Uninstallation rpm file on Node.

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

package "git" do
action :remove
end
[root@chef-workstation recipes]#
[root@chef-workstation recipes]#  knife cookbook upload git
Uploading git            [0.1.0]
Uploaded 1 cookbook.
[root@chef-workstation recipes]#

Node1: 

[root@node1 chef]# chef-client
Chef Infra Client, version 17.10.3
Patents: https://www.chef.io/patents
Infra Phase starting
Resolving cookbooks for run list: ["git"]
Synchronizing cookbooks:
  - git (0.1.0)
Installing cookbook gem dependencies:
Compiling cookbooks...
Loading Chef InSpec profile files:
Loading Chef InSpec input files:
Loading Chef InSpec waiver files:
Converging 1 resources
Recipe: git::default
  * yum_package[git] action remove
    - remove package git

Running handlers:
Running handlers complete
Infra Phase complete, 1/1 resources updated in 18 seconds
[root@node1 chef]#

----------------------------End of Example7---------------------------------------

Cookbook Recipe : 8

Comments

Popular posts from this blog

To change the data directory location for PostgreSQL after installation

AWR

GIT