0

I wanted to extract value from a file and then put it into an attribute.

eg. let the file be /app/ABC/.ssh/id_rsa.pub and

the attribute be default['sample_cookbook']['auth_keys']

I would like the value(s) in id_rsa.pub set into the above attribute.

srajappa
  • 425
  • 6
  • 16

1 Answers1

2

See this answer for more information on how to read data from files.

For this case, since id_rsa.pub is probably only on the order of a few kB, you can just use

default = {'sample_cookbook' => {'auth_keys' => File.read("/app/ABC/.ssh/id_rsa.pub") }}
Glyoko
  • 1,963
  • 12
  • 26
  • so, I understood your answer and wrote this following statement- It worked just fine. `default['sample_cookbook']['auth_keys'] = ::File.read("/app/ABC/.ssh/id_rsa.pub")` – srajappa Feb 21 '17 at 23:25
  • 3
    Just remember that this happens when the file is executed, not when you use the attribute. – coderanger Feb 22 '17 at 00:07