To verify current chef client version we can use the below command
Chef-shell --version
We will get output like
Chef Infra Client : 18.4.12
1. Go to cookbooks
cd ~/cookbooks/
2. Create a directory for cookbook and recipe using the following structure.
mkdir -p downloads/recipes
3. Go to the directory
cd downloads/recipes
4. Create a below file to download file
vi FileDownload.rb
5. Paste the below content in the file Filedownload.rb
#Cookbook : downloads
#Recipe : FileDownload.rb
#To Download the file from artifactory using the curl script
execute 'Download File'
user 'root'
command 'curl -o ~/cookbooks/downloads/recipes/File.txt -O https://artifactory.srv.mytest.com.au/application/env/File.txt'
live_stream true
action : run
end
6. Save the file using esc+:wq and run using the below command
chef-client -zr recipe[downloads::FileDownload]
7. Alternatively we can run the chef cookbook using below command
chef-client --local-mode --runlist 'recipe[downloads::FileDownload]'
8. We can use native chef resource to download the file
#Cookbook : downloads
#Recipe : FileDownload.rb
#To Download the file from artifactory chef resource and keep in required folder
remote_file '/tmp/File.txt' do
source 'https://artifactory.srv.mytest.com.au/application/env/File.txt'
owner 'root'
group 'root'
action :create
end
execute 'move file' do
command 'mv /tmp/File.txt ~/cookbooks/downloads/recipes/File.txt'
action :run
not_if {::File.exist?('~/cookbooks/downloads/recipes/File.txt')}
end
No comments:
Post a Comment