Unable to set the node attributes within a ruby block

115 Views Asked by At

I have exactly the same code as suggested in the given link by @StephenKing (https://stackoverflow.com/users/400222/stephenking) and although the command works and gives the correct return value (verified using log/print) the value is not set in the attribute. Did something significantly change over the years? How to get a linux command output to chef attribute

ruby_block "something" do
    block do
        #tricky way to load this Chef::Mixin::ShellOut utilities
        Chef::Resource::RubyBlock.send(:include, Chef::Mixin::ShellOut)      
        command = 'cat /etc/hostname'
        command_out = shell_out(command)
        node.default['my_attribute'] = command_out.stdout
    end
    action :create
end

Note: I also tried with node.force_default to set the value and that didn't set the value either.

0

There are 0 best solutions below