Cookbook Recipe : 2
Example2: Creating a directory
Chef-workstation server:
[root@chef-workstation opt]# cd /opt/chef/chef-starter/chef-repo/cookbooks/cookbook1/recipes
[root@chef-workstation recipes]# vi default.rb
[root@chef-workstation recipes]# cat default.rb
#
# Cookbook:: cookbook1
# Recipe:: default
#
# Copyright:: 2022, The Authors, All Rights Reserved.
directory "/opt/chef_dir_creation" do
action :create
end
[root@chef-workstation recipes]#
[root@chef-workstation recipes]# knife cookbook upload cookbook1
Uploading cookbook1 [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: ["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
* directory[/opt/chef_dir_creation] action create
- create new directory /opt/chef_dir_creation
- restore selinux security context
Running handlers:
Running handlers complete
Infra Phase complete, 1/1 resources updated in 19 seconds
[root@node1 chef]# ls -lrt /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
drwxr-xr-x. 2 root root 6 May 7 12:34 chef_dir_creation
[root@node1 chef]#
----------------------------End of Example2---------------------------------------
Comments
Post a Comment