Cookbook Recipe : 4

 

Example4: Deleting a file with Automatic chef-client run for every 2 mins on Node-1

Node1: 

"chef-client" - command save in chef.sh

[root@node1 chef_dir_creation]# vi chef.sh
[root@node1 chef_dir_creation]# chmod +x chef.sh
[root@node1 chef_dir_creation]# cat chef.sh
chef-client
[root@node1 chef_dir_creation]#

running this file using crontab , script " /opt/chef_dir_creation/chef_file.sh" will for every 2 mins

[root@node1 chef_dir_creation]# crontab -e
crontab: installing new crontab
[root@node1 chef_dir_creation]# crontab -l
*/2 * * * * /opt/chef_dir_creation/chef_file.sh
[root@node1 chef_dir_creation]# 

Chef-workstation server:

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

file "/opt/chef_dir_creation/chef_file" do
action :delete
end
[root@chef-workstation recipes]# knife cookbook upload cookbook1
Uploading cookbook1      [0.1.0]
Uploaded 1 cookbook.
[root@chef-workstation recipes]#

Verify "chef_file" will deleted automatically on Node-1: 

[root@node1 chef_dir_creation]# date
Sat May  7 13:27:01 IST 2022
[root@node1 chef_dir_creation]# ls -ltr
total 8
-rw-r--r--. 1 root root 33 May  7 12:51 chef_file
-rwxr-xr-x. 1 root root 12 May  7 13:22 chef.sh
[root@node1 chef_dir_creation]# date
Sat May  7 13:27:21 IST 2022
[root@node1 chef_dir_creation]# date
Sat May  7 13:28:26 IST 2022
You have new mail in /var/spool/mail/root
[root@node1 chef_dir_creation]# ls -ltr
total 4
-rwxr-xr-x. 1 root root 12 May  7 13:22 chef.sh

----------------------------End of Example4---------------------------------------

Cookbook Recipe : 5

Comments

Popular posts from this blog

To change the data directory location for PostgreSQL after installation

AWR

GIT