Chef set node attribute value from a regex matching

208 Views Asked by At

I am trying to set node attribute with sub string from a file, but I am not able to achieve that successfully.

Content of #{ENV['TEMP']}\fullname.txt is

Full Name        King Arthur

And I want to assign only "King Arthur" to node attribute node.default[user_name]

This is the ruby_block I am trying

ruby_block 'test' do
  block do
   fullname = ::File.read("#{ENV['TEMP']}\\fullname.txt")
   node.default['user_name']  = "#{fullname.split("Full Name")[1].strip}"
  end
end

Nothing gets assigned to this node attribute.

0

There are 0 best solutions below