Cookbook Recipe : 3
Example3: Creating a File with content
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]# cat default.rb
#
# Cookbook:: cookbook1
# Recipe:: default
#
# Copyright:: 2022, The Authors, All Rights Reserved.
file "/opt/chef_dir_creation/chef_file" do
action :create
content "add the content to file chef_file"
end
[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
* file[/opt/chef_dir_creation/chef_file] action create
- create new file /opt/chef_dir_creation/chef_file
- update content in file /opt/chef_dir_creation/chef_file from none to 3495e0
--- /opt/chef_dir_creation/chef_file 2022-05-07 12:51:25.978217591 +0530
+++ /opt/chef_dir_creation/.chef-chef_file20220507-4089-gkncyu 2022-05-07 12:51:25.976217591 +0530
@@ -1 +1,2 @@
+add the content to file chef_file
- restore selinux security context
Running handlers:
Running handlers complete
Infra Phase complete, 1/1 resources updated in 15 seconds
[root@node1 chef]# cd /opt/chef_dir_creation/
[root@node1 chef_dir_creation]# ls -lrt
total 4
-rw-r--r--. 1 root root 33 May 7 12:51 chef_file
[root@node1 chef_dir_creation]# cat chef_file
add the content to file chef_file
[root@node1 chef_dir_creation]#
----------------------------End of Example3---------------------------------------
Comments
Post a Comment