I am trying to add something to the hostfile of my node through the chef cookbook and my node is a Windows Server.
I am using the following cookbook
hostsfile_entry ‘2.3.4.5’ do
hostname 'www.example.com’
unique true
end
But when I upload this cookbook and run chef-client on my Windows node it says " No such file or directory @ rb_sysopen - /etc/hosts". Is it because this cookbook is only for linux machine and not for Windows.
Have you defined the path attribute for your windows nodes? The default is nil, and my guess (without searching the full code) is that if the attribute is nil that the recipe will look at /etc/hosts.
default[‘hostsfile’][‘path’] = 'C:/Windows/System32/drivers/etc/hosts’
This is the way i have specified in th eattributes/default.rb
But how to specify this in the cookbook.
If using the latest version of customink-webops/hostsfile then you shouldn’t even need to set node['hostsfile']['path'] as it has logic in the library to do this for you.
That said setting the attribute for the path can be done many ways including in the cookbook itself, a wrapper cookbook, a role, an environment, or you could set the attribute on the node itself.
If you’d like some more interactive assistance join us in the Slack channel.