Hostfile cookbook for editing the hostfile of a node


#1

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.


#2

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.


#3

Which hosts file cookbook are you using? There are 3 listed on the supermarket

https://supermarket.chef.io/cookbooks?utf8=✓&q=hostfile&platforms[]=

If using the customink-webops cookbook, it requires that you set an attribute default['hostsfile']['path'] = nil


#4

I have been using the hostfile cookbook provided by sethvargo. I like how
it provides a lightweight wrapper.


#5

https://supermarket.chef.io/cookbooks/hostsfile#readme

I am using this cookbook . Here there is no attribute to specify the path of the host file.


#6

This hostfile cookbook I have used
https://supermarket.chef.io/cookbooks/hostsfile#readme


#7

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.


#8

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.

-cheeseplus