Skip to content

Instantly share code, notes, and snippets.

@charlesjohnson
Last active November 4, 2019 05:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlesjohnson/9d6f3e0fca1fa4602257 to your computer and use it in GitHub Desktop.
Save charlesjohnson/9d6f3e0fca1fa4602257 to your computer and use it in GitHub Desktop.
Get bash / execute output from Chef
#!/opt/chefdk/bin/chef-apply
# Lifted pretty much verbatim from http://stackoverflow.com/questions/17813592/how-can-i-display-the-output-of-a-opscode-chef-bash-command-in-my-console)
results = "/tmp/output.txt"
file results do
action :delete
end
cmd = "ls /"
bash cmd do
code <<-EOH
#{cmd} &> #{results}
EOH
end
ruby_block "Results" do
only_if { ::File.exists?(results) }
block do
print "\n"
print File.read(results)
end
end
@vbasavar
Copy link

vbasavar commented Nov 4, 2019

Thanks for the suggestion. I will try your approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment