Skip to content

Instantly share code, notes, and snippets.

@juliandunn
Created August 15, 2014 03:40
Show Gist options
  • Save juliandunn/abdd56b91cce29e8e9f2 to your computer and use it in GitHub Desktop.
Save juliandunn/abdd56b91cce29e8e9f2 to your computer and use it in GitHub Desktop.
How do you set a node attribute to the value of stdout from a shell command?
% chef-apply -l info recipe.rb
[2014-08-14T23:38:46-04:00] INFO: Run List is []
[2014-08-14T23:38:46-04:00] INFO: Run List expands to []
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* ruby_block[demo] action run[2014-08-14T23:38:46-04:00] INFO: Processing ruby_block[demo] action run ((chef-apply cookbook)::(chef-apply recipe) line 2)
[2014-08-14T23:38:46-04:00] INFO: ruby_block[demo] called
- execute the ruby block demo
* log[demo] action write[2014-08-14T23:38:46-04:00] INFO: Processing log[demo] action write ((chef-apply cookbook)::(chef-apply recipe) line 9)
[2014-08-14T23:38:46-04:00] INFO: Hello world
Chef::Resource::RubyBlock.send(:include, Chef::Mixin::ShellOut)
ruby_block "demo" do
block do
s = shell_out("echo Hello world")
node.default['foo'] = s.stdout
end
end
log "demo" do
message lazy { node['foo'] }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment