Writing a file from within a recipe to the Chef server


#1

Hello Everybody!
I’m writing a recipe (for Windows nodes) that I want to help populate a properties.yml file so I can use it with some serverspec tests that I want to run once the Chef run has completed.
I can get hold of the attributes required and dump them into a file, but it’s saving this file on the nodes in question, whereas I need it on the Chef Server itself.
Is this even possible to do? Minitest handler is out of the question as there is no support for Windows, any suggestions?

Currently I am using:
"ruby_block “nodes for serverspec” do
block do
if ::File.exist?(‘properties.yml’) then
::File.delete(‘properties.yml’)
end
cnnodes.each do |n|
mess = <<EOH
#{n}:
:roles:
- console
EOH
::File.open(‘properties.yml’, “a”) { |f| f.write(mess)}
end
end
end"
Where cnnodes is an array of the node names for a particular server role.

Thanks
Chris


#2

Hi Chris,

My suggestion would be to create a node attribute which will saved in chef
server.

cnnodes.each *do *|n|

mess *= *<<EOH

#{n}:

:roles:

- console

EOH
node.set[“node_properties”] = mess

Thanks,
Saheb

On Tue, Jul 14, 2015 at 3:42 PM, ChristopherHall@air-watch.com <
ChristopherHall@air-watch.com> wrote:

Hello Everybody!

I’m writing a recipe (for Windows nodes) that I want to help populate a
properties.yml file so I can use it with some serverspec tests that I want
to run once the Chef run has completed.

I can get hold of the attributes required and dump them into a file, but
it’s saving this file on the nodes in question, whereas I need it on the
Chef Server itself.

Is this even possible to do? Minitest handler is out of the question as
there is no support for Windows, any suggestions?

Currently I am using:

“ruby_block “nodes for serverspec” do

block do

  • if *::File.exist?(‘properties.yml’) then
::*File*.delete('properties.yml')

end

cnnodes.each *do *|n|

mess *= *<<EOH

#{n}:

:roles:

- console

EOH

::*File*.open('properties.yml', "a") { *|*f*| *f.write(mess)}

end

end

end

Where cnnodes is an array of the node names for a particular server role.

Thanks

Chris