Cookbook Recipe : 1
Example1:- Creating a file
chef-workstation server:
[root@chef-workstation recipes]# cd /opt/chef/chef-starter/chef-repo/cookbooks/cookbook1/recipes
[root@chef-workstation recipes]# vi default.rb
[root@chef-workstation recipes]#
[root@node1 chef]#
# Cookbook:: cookbook1
# Recipe:: default
#
# Copyright:: 2022, The Authors, All Rights Reserved.
file "/opt/file_creation" do
end
[root@chef-workstation recipes]# knife cookbook upload cookbook1
Uploading cookbook1 [0.1.0]
Uploaded 1 cookbook.
Node-1 :
[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: ["cookbook1"]
Synchronizing cookbooks:
- cookbook1 (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: cookbook1::default
* file[/opt/file_creation] action create
- create new file /opt/file_creation
- restore selinux security context
Chef Infra Client, version 17.10.3
Patents: https://www.chef.io/patents
Infra Phase starting
Resolving cookbooks for run list: ["cookbook1"]
Synchronizing cookbooks:
- cookbook1 (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: cookbook1::default
* file[/opt/file_creation] action create
- create new file /opt/file_creation
- restore selinux security context
Running handlers:
Running handlers complete
Infra Phase complete, 1/1 resources updated in 16 seconds
[root@node1 chef]#
Verifying file creation:
[root@node1 chef]# ls -rlt /opt
total 0
drwxr-xr-x. 3 root root 65 Apr 25 12:13 java
drwxr-xr-x. 5 root root 103 Apr 25 15:25 maven
drwxr-xr-x. 10 root root 283 Apr 25 20:32 tomcat
drwxr-xr-x. 5 root root 121 May 5 20:51 chef
-rw-r--r--. 1 root root 0 May 7 12:15 file_creation
[root@node1 chef]#
----------------------------End of Example1---------------------------------------
Comments
Post a Comment