I am trying to run a ruby script with /opt/chef-server/embedded/bin/ruby
interpreter during chef-client run.
This works:
execute ‘process_something’ do
action :run
command '/opt/chef-server/embedded/bin/ruby
/usr/local/bin/process_something.rb’
end
These do not work:
ruby ‘process_something’ do
action :run
command '/opt/chef-server/embedded/bin/ruby
/usr/local/bin/process_something.rb’
end
and
ruby ‘process_something’ do
action :run
command '/usr/local/bin/process_something.rb’
end
I run the cookbook with ‘-l debug’ but eventually got only:
[2015-03-19T14:24:41+00:00] INFO: ruby[process_something] ran successfully
in the logs.
Can anyone tell me how to run a ruby script during chef-client run with
interpreter from /opt/chef-server/embedded/bin/ruby or
/opt/chef/embedded/bin/ruby?
I know that I can use ruby_code resource but I am under impression that it
should be used rather for blocks of ruby code and not for scripts, is it so?
So yes, the ruby_block resource is for an inline block of Ruby code you want to run within the context of the Chef execution.
As for your execute resource, that appears to a way to do it. Curious though; is there any reason you wouldn’t write your script as a library for your cookbook, and then use the ruby_block resource to execute it? Do you need the script outside of the scope of Chef convergences?
–
Jeff Byrnes @thejeffbyrnes
Lead DevOps Engineer
EverTrue
704.516.4628
I am trying to run a ruby script with /opt/chef-server/embedded/bin/ruby interpreter during chef-client run.
This works:
execute ‘process_something’ do
action :run
command '/opt/chef-server/embedded/bin/ruby /usr/local/bin/process_something.rb’
end
These do not work:
ruby ‘process_something’ do
action :run
command '/opt/chef-server/embedded/bin/ruby /usr/local/bin/process_something.rb’
end
and
ruby ‘process_something’ do
action :run
command '/usr/local/bin/process_something.rb’
end
I run the cookbook with ‘-l debug’ but eventually got only:
[2015-03-19T14:24:41+00:00] INFO: ruby[process_something] ran successfully
in the logs.
Can anyone tell me how to run a ruby script during chef-client run with interpreter from /opt/chef-server/embedded/bin/ruby or /opt/chef/embedded/bin/ruby?
I know that I can use ruby_code resource but I am under impression that it should be used rather for blocks of ruby code and not for scripts, is it so?
I like rather to have the script outside of chef, it is easier to perform
troubleshooting (from my point of view) then and also in case of change in
automation solution (for example a move to puppet) smaller amount of
changes is needed to move the script to the new environment
So yes, the ruby_block resource is for an inline block of Ruby code you
want to run within the context of the Chef execution.
As for your execute resource, that appears to a way to do it. Curious
though; is there any reason you wouldn’t write your script as a library for
your cookbook, and then use the ruby_block resource to execute it? Do you
need the script outside of the scope of Chef convergences?
I am trying to run a ruby script with /opt/chef-server/embedded/bin/ruby
interpreter during chef-client run.
This works:
execute 'process_something' do
action :run
command '/opt/chef-server/embedded/bin/ruby
/usr/local/bin/process_something.rb'
end
These do not work:
ruby 'process_something' do
action :run
command '/opt/chef-server/embedded/bin/ruby
/usr/local/bin/process_something.rb'
end
and
ruby 'process_something' do
action :run
command '/usr/local/bin/process_something.rb'
end
I run the cookbook with '-l debug' but eventually got only:
[2015-03-19T14:24:41+00:00] INFO: ruby[process_something] ran successfully
in the logs.
Can anyone tell me how to run a ruby script during chef-client run with
interpreter from /opt/chef-server/embedded/bin/ruby or
/opt/chef/embedded/bin/ruby?
I know that I can use ruby_code resource but I am under impression that it
should be used rather for blocks of ruby code and not for scripts, is it so?
this is as expected. ruby_block runs raw ruby code specified via the code
attribute. For arbitrary script, use the execute resources, given you are
specifying the ruby interpreter, its just any other command.
I like rather to have the script outside of chef, it is easier to perform
troubleshooting (from my point of view) then and also in case of change in
automation solution (for example a move to puppet) smaller amount of
changes is needed to move the script to the new environment
So yes, the ruby_block resource is for an inline block of Ruby code you
want to run within the context of the Chef execution.
As for your execute resource, that appears to a way to do it. Curious
though; is there any reason you wouldn’t write your script as a library for
your cookbook, and then use the ruby_block resource to execute it? Do you
need the script outside of the scope of Chef convergences?
I am trying to run a ruby script with /opt/chef-server/embedded/bin/ruby
interpreter during chef-client run.
This works:
execute 'process_something' do
action :run
command '/opt/chef-server/embedded/bin/ruby
/usr/local/bin/process_something.rb'
end
These do not work:
ruby 'process_something' do
action :run
command '/opt/chef-server/embedded/bin/ruby
/usr/local/bin/process_something.rb'
end
and
ruby 'process_something' do
action :run
command '/usr/local/bin/process_something.rb'
end
I run the cookbook with '-l debug' but eventually got only:
[2015-03-19T14:24:41+00:00] INFO: ruby[process_something] ran successfully
in the logs.
Can anyone tell me how to run a ruby script during chef-client run with
interpreter from /opt/chef-server/embedded/bin/ruby or
/opt/chef/embedded/bin/ruby?
I know that I can use ruby_code resource but I am under impression that
it should be used rather for blocks of ruby code and not for scripts, is it
so?