lundi 25 avril 2016

How to assign file content to chef node attribute

I have fingreprint.txt at the location "#{node['abc.d']}/fingreprint.txt"

The contents of the file are as below:
time="2015-03-25T17:53:12C" level=info msg="SHA1 Fingerprint=7F:D0:19:C5:80:42:66"

Now I want to retrieve the value of fingerprint and assign it to chef attribute
I am using the following ruby block

ruby_block "retrieve_fingerprint" do  
    block do  
        path="#{node['abc.d']}/fingreprint.txt"  
        Chef::Resource::RubyBlock.send(:include, Chef::Mixin::ShellOut)  
        command = 'grep -Po '(?<=Fingerprint=)[^"]*' path '  
        command_out = shell_out(command)  
        node.default['fingerprint'] = command_out.stdout  
    end  
    action :create  
end  

It seems not to be working because of missing escape chars. Please let me know if there is some other way of assigning file content to node attribute

Aucun commentaire:

Enregistrer un commentaire