I have a chef recipe that looks something like:
Chef::Log.info('step1')
# do stuff
Chef::Log.info('step2')
bash "do_wget" do
code <<-EOF
wget somefile
EOF
end
Chef::Log.info('step3')
# do stuff
The wget takes a while but the logging ends up looking like
step1
step2
step3
bash script runs #indicates that the bash script from step 2 is running
Is there a way to prevent the logging from step3 until the bash script is done executing?
The simplest way to view a Chef log is to go to the instance's details page. The Logs section includes an entry for each event and Execute Recipes command. The following shows an instance's Logs section, with configure and setup commands, which correspond to Configure and Setup lifecycle events.
You can use which knife or which chef-client to determine (exist status 0 : command found, otherwise 1 ). While knife is used on the workstation, it should come with every installation of chef. But to be save, check for chef-client .
Installing Packages from Third-Party RepoStep 1 − Edit the default recipe of the cookbook. Step 2 − Edit the metadata to add dependency on the apt cookbook. Step 3 − Upload the modified cookbook to the Chef server. Step 4 − Validate that the package you are trying to install, is not yet installed.
The chef client can be used in local mode to test cookbooks or in a single server setup, or it can be connected with a Chef Infra Server, a tool that can be used to centrally manage many clients on different VMs. It uses cookbooks to act as infrastructure as code and dictate the state of the system.
You should get acquainted with Anatomy of Chef Run. It has 2 stages: compiling and executing.
No action is taken on the resources in the recipes at compiling stage - each evaluated resource is just taken and put into the Resource Collection. Plain Ruby code outside of resources is evaluated, however.
In execution stage it actually evaluates Resource Collection. But by this moment all your logging messages are already printed out.
If you need to run ruby code (including Chef logging) on execution stage, there is a special resource for that Ruby Block
ruby_block "Add logging step3" do
block do
Chef::Log.info('step3')
end
action :create
end
Another way may be, is to actually execute resource in compiling stage:
bash "do_wget" do
code "wget somefile"
action :nothing
end.run_action :run
Action :nothing is set to avoid running this resource twice (once in every stage).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With