在厨师中从文件中提取值并将值设置为属性

Extracting value from a file and setting value to attribute, in chef

我想从 文件 中提取值,然后将其放入属性中。

例如。让文件成为 /app/ABC/.ssh/id_rsa.pub

属性为default['sample_cookbook']['auth_keys']

我想将 id_rsa.pub 中的值设置到上述属性中。

有关如何从文件中读取数据的详细信息,请参阅 this answer

对于这种情况,由于id_rsa.pub可能只有几kB的数量级,你可以直接使用

default = {'sample_cookbook' => {'auth_keys' => File.read("/app/ABC/.ssh/id_rsa.pub") }}