Adoptable Cookbooks List

Looking for a cookbook to adopt? You can now see a list of cookbooks available for adoption!
List of Adoptable Cookbooks

Supermarket Belongs to the Community

Supermarket belongs to the community. While Chef has the responsibility to keep it running and be stewards of its functionality, what it does and how it works is driven by the community. The chef/supermarket repository will continue to be where development of the Supermarket application takes place. Come be part of shaping the direction of Supermarket by opening issues and pull requests or by joining us on the Chef Mailing List.

Select Badges

Select Supported Platforms

Select Status


hostsfile (22) Versions 3.0.1

Provides an resource for managing the /etc/hosts file

cookbook 'hostsfile', '~> 3.0.1', :supermarket
cookbook 'hostsfile', '~> 3.0.1'
knife supermarket install hostsfile
knife supermarket download hostsfile
Quality 17%

hostsfile cookbook

Build Status

hostsfile provides a resource for managing your /etc/hosts (or Windows equivalent) file using Chef.


  • Chef 12.7 or higher


Attribute Description Example Default
ip_address (name attribute) the IP address for the entry
hostname (required) the hostname associated with the entry
unique remove any existing entries that have the same hostname true false
aliases array of aliases for the entry [''] []
comment a comment to append to the end of the entry 'interal DNS server' nil
priority the relative position of this entry 20 (varies, see Priorities section)


Please note: In v0.1.2, specifying a hostname or alias that existed in another automatically removed that hostname from the other entry before. In v2.1.0, the unique option was added to give the user case-by-case control of this behavior. For example, given an /etc/hosts file that contains:

when the Chef recipe below is converged:

hostsfile_entry '' do
  hostname  ''
  unique    true

then the /etc/hosts file will look like this:

Not specifying the unique parameter will result in duplicate hostsfile entries.


Creates a new hosts file entry. If an entry already exists, it will be overwritten by this one.

hostsfile_entry '' do
  hostname  ''
  action    :create

This will create an entry like this:


Create a new hosts file entry, only if one does not already exist for the given IP address. If one exists, this does nothing.

hostsfile_entry '' do
  hostname  ''
  action    :create_if_missing


Append a hostname or alias to an existing record. If the given IP address doesn't already exist in the hostsfile, this method behaves the same as create. Otherwise, it will append the additional hostname and aliases to the existing entry. # Created by Chef
hostsfile_entry '' do
  hostname  ''
  aliases   ['', '']
  comment   'Append by Recipe X'
  action    :append

would yield: # Created by Chef, Appended by Recipe X


Updates the given hosts file entry. Does nothing if the entry does not exist.

hostsfile_entry '' do
  hostname  ''
  comment   'Update by Chef'
  action    :update

This will create an entry like this:           example # Updated by Chef


Removes an entry from the hosts file. Does nothing if the entry does not exist.

hostsfile_entry '' do
  action    :remove

This will remove the entry for


If you're using Berkshelf, just add hostsfile to your Berksfile:

cookbook 'hostsfile'

Otherwise, install the cookbook from the community site:

knife cookbook site install hostsfile

Have any other cookbooks depend on hostsfile by editing editing the metadata.rb for your cookbook.

# metadata.rb
depends 'hostsfile'

Note that you can specify a custom path to your hosts file in the ['hostsfile']['path'] node attribute. Otherwise, it defaults to sensible paths depending on your OS.


If you are using ChefSpec to unit test a cookbook that implements the hostsfile_entry resource, this cookbook packages customer matchers that you can use in your unit tests:

  • append_hostsfile_entry
  • create_hostsfile_entry
  • create_hostsfile_entry_if_missing
  • remove_hostsfile_entry
  • update_hostsfile_entry

For example:

it 'creates a hostsfile entry for the DNS server' do
  expect(chef_run).to create_hostsfile_entry('')


Priority is a relatively new addition to the cookbook. It gives you the ability to (somewhat) specify the relative order of entries. By default, the priority is calculated for you as follows:

  2. ::1
  4. IPV4
  5. IPV6
  6. default

However, you can override it using the priority option.

License & Authors

Copyright 2012-2013, Seth Vargo
Copyright 2012, CustomInk, LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.

Dependent cookbooks

This cookbook has no specified dependencies.

Contingent cookbooks

arcgis-enterprise Applicable Versions
archlinux Applicable Versions
baseserver Applicable Versions
chef_dnsmasq Applicable Versions
cloudbees-cjp-ha Applicable Versions
common_linux Applicable Versions
corosync Applicable Versions
corosync-cookbook Applicable Versions
dirsrv Applicable Versions
foreman Applicable Versions
fqdn Applicable Versions
ganeti Applicable Versions
gemirro Applicable Versions
gotcms Applicable Versions
hostname Applicable Versions
hostname-chef13 Applicable Versions
hostnames Applicable Versions
kagent Applicable Versions
letsencrypt-boulder-server Applicable Versions
lxmx_hostname Applicable Versions
opennms Applicable Versions
pacemaker Applicable Versions
paramount Applicable Versions
postgresql-cluster Applicable Versions
riak-cluster Applicable Versions
server_utils Applicable Versions
singularity Applicable Versions
stackstorm Applicable Versions
supermarket-omnibus-cookbook Applicable Versions
system Applicable Versions
wazuh Applicable Versions
wazuh_agent Applicable Versions
wazuh_manager Applicable Versions
websrv Applicable Versions

hostsfile Cookbook CHANGELOG

This file is used to list changes made in each version of the hostsfile cookbook.

v3.0.1 (2017-08-22)

  • Add and files
  • Fix the readme to properly specify Chef 12.7+ as the Chef requirement
  • Add a local delivery configuration and remove the existing rakefile
  • Resolve most of the ChefSpec failures

v3.0.0 (2017-08-22)

  • Converted the LWRP to a custom resource which increases the required Chef release to 12.7
  • Namespaced the helper libraries under the HostsFile module to prevent method collisions with other resources or the chef-client itself

v2.4.6 (2017-08-15)

  • use openssl for FIPS compatibility
  • Expand priority documentation in README
  • Add ::1 loopback to test cases and priority settings

v2.4.5 (2014-06-24)

  • Fix notifications and why-run mode

v2.4.4 (2014-02-25)

  • Bump Berkshelf version
  • Remove scope pieces from IPv6 addresses

v2.4.3 (2014-02-01)

  • Package custom ChefSpec matchers
  • Update testing harness
  • Avoid using Chef::Application.fatal!
  • Use Chef::Resource::File for atomic updates


  • Fix Travis CI integration
  • Remove newline characters
  • Allow specifying a custom hostsfile path


  • Force a new upload to the community site


  • Convert everything to Ruby 1.9 syntax because I'm tired of people removing trailing commas despite the massive warning in the README: (#29, #30, #32, #33, #34, #35, #36, #38, #39)
  • Update to the latest and greatest testing gems and practices
  • Remove strainer in favor of a purer solution
  • Update .gitignore to ignore additional files
  • Add more platforms to the .kitchen.yml
  • Use converge_by and support whyruny mode


  • Completely manage the hostsfile, ensuring no duplicate entries


  • Support Windows (thanks @igantt-daptiv)
  • Specs + Travis support
  • Throw fatal error if hostsfile does not exist (@jkerzner)
  • Write priorities in hostsfile so they are read on subsequent Chef runs


  • Updated README to require Ruby 1.9
  • Allow hypens in hostnames
  • Ensure newline at end of file
  • Allow priority ordering in hostsfile


  • Fixed issue #1
  • Better unique object filtering
  • Better handing of aliases


  • Initial release

Collaborator Number Metric

3.0.1 failed this metric

Failure: Cookbook has 1 collaborators. A cookbook must have at least 2 collaborators to pass this metric.

Contributing File Metric

3.0.1 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of, and your repo must contain a file

Cookstyle Metric

3.0.1 failed this metric

Chef/Deprecations/ResourceWithoutUnifiedTrue: Set `unified_mode true` in Chef Infra Client 15.3+ custom resources to ensure they work correctly in Chef Infra Client 18 (April 2022) when Unified Mode becomes the default. ( hostsfile/resources/entry.rb: 1
Chef/Modernize/DefinesChefSpecMatchers: ChefSpec matchers are now auto generated by ChefSpec 7.1+ and do not need to be defined in a cookbook ( hostsfile/libraries/matchers.rb: 1

Run with Cookstyle Version 7.32.1 with cops Chef/Deprecations,Chef/Correctness,Chef/Sharing,Chef/RedundantCode,Chef/Modernize,Chef/Security,InSpec/Deprecations

No Binaries Metric

3.0.1 passed this metric

Testing File Metric

3.0.1 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of, and your repo must contain a file

Version Tag Metric

3.0.1 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of, and your repo must include a tag that matches this cookbook version number