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

The chef_hostname cookbook has been deprecated

Author provided reason for deprecation:

The chef_hostname cookbook has been deprecated and is no longer being maintained by its authors. Use of the chef_hostname cookbook is no longer recommended.


chef_hostname (14) Versions 0.6.0

Configures the hostname on a node

cookbook 'chef_hostname', '= 0.6.0', :supermarket
cookbook 'chef_hostname', '= 0.6.0'
knife supermarket install chef_hostname
knife supermarket download chef_hostname
Quality 100%

chef_hostname Cookbook

Sets the node's hostname

  • resource-driven cookbook
  • supports FQDNs as hostnames
  • persists after a reboot
  • reloads ohai
  • runs at compile-time (no need to use lazy)
  • fixes up /etc/hosts so node["fqdn"] works
  • runs nearly everywhere
  • supports hostnamectl from systemd
  • not tied to any other sysctl/etc-hosts cookbook dependecies


  • Make strong guarantees that node["fqdn"] in other recipes "just works"
  • No need to lazy { node["fqdn"] }
  • Be very portable



  • Ubuntu/Debian (and derivatives like Mint/Raspbian)
  • RHEL/CentOS/Scientific/Oracle/Fedora (and derivatives like Pidora)
  • FreeBSD/OpenBSD/NetBSD
  • Docker Containers
  • MacOS
  • Solaris
  • Gentoo
  • Arch
  • Cisco Nexus
  • Windows <-- currently a bit of a lie

Because of the way that this cookbook "Duck Types" the operating system, many systems that are not listed above have a decent chance of working out of the box provided that they implement a common pattern.


  • Chef 12.7+


  • none

Custom Resources

hostname Sets the hostname, ensures that reboot will preserve the hostname, re-runs the ohai plugin to set the node data.


  • :set: Ses the hostname


  • hostname: hostname to set
  • compile_time: defaults to running at compile time, set to false to disable

Chefspec / Testing

The action to be used in Chefspec/tests is "set" for exmaple:

      it 'checks if hostname is being set' do
        expect(chef_run).to set_hostname('')


Setting hostname to a string:

hostname ""

Setting hostname to the node name:


Setting hostname to whatever attribute you like:

hostname node['set_fqdn']

There is no need to "lazy" arguments to templates and filenames when this is used since it forces itself to run at compile-time.


# node["fqdn"] will be set here at compile time
template "/etc/motd" do
  source "motd.erb"
    fqdn: node["fqdn"]

# /bin/hostname will be set here at compile time
myhostname = `/bin/hostname`

file "/etc/issue" do
  content myhostname

The hostname resource will drop a line into /etc/hosts so that the node["fqdn"] can be resolved correctly, and will re-trigger ohai. The default is to use the node["ipaddress"]` value for the ipaddress on the /etc/hosts line. In order to override it:

hostname node["cloud"]["public_hostname"]
  ipaddress node["cloud"]["public_ipv4"]

In order to override the editing of the /etc/hosts file pass nil for the ipaddress (note that if you edit the /etc/hosts file you will be responsible for also reloading the ohai plugin and you will want to do both at compile-time yourself in order for node["fqdn"] to resolve)

  ipaddress nil

Aliases can also be added to the line that hostname adds to /etc/hosts:

  ipaddress ""
  aliases [ "", "yolo" ]


There are no recipes in this cookbook, the resource is meant to be used in your own custom recipes. There are no attributes in this cookbook, you can drive the resource off of whatever attribute(s) you like.

Docker container hostnames do not persist after restarts due to limitations of docker.


  • fix setting node['fqdn'] correctly on windows
  • aix
  • xenserver (probably already supported via RHEL)
  • test: exherbo, alpine, slackware, rapsbian, pidora
  • smartos, omnios, openindiana, opensolaris, nexentacore?

License & Authors

Author:: Lamont Granquist ()

Copyright:: 2016-2016, Chef Software, Inc

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

There are no cookbooks that are contingent upon this one.

chef_hostname Cookbook CHANGELOG

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

0.6.0 (2017-05-30)

  • Added testing in Travis with Delivery local mode
  • Require Chef 12.7+ in order to be Chef 13 compatible
  • Use a SPDX standard license string

0.5.0 (2017-02-27)

Full Changelog

Closed issues:

  • Missing dbus dependency on Ubuntu 16.04 LTS? #25
  • cloud-init resets hostname #23

Merged pull requests:

v0.4.2 (2016-09-19)

Full Changelog

Closed issues:

  • Multiple HOSTNAME lines added to /etc/sysconfig/network (CentOS 6.7) #16

Merged pull requests:

v0.4.1 (2016-04-05)

Full Changelog

Merged pull requests:

v0.4.0 (2016-03-22)

Full Changelog

Merged pull requests:

v0.3.1 (2016-03-21)

Full Changelog

Merged pull requests:

v0.3.0 (2016-03-11)

Full Changelog

Merged pull requests:

v0.2.0 (2016-03-11)

Full Changelog

Merged pull requests:

v0.1.2 (2016-03-11)

Full Changelog

v0.1.1 (2016-03-11)

Full Changelog

Merged pull requests:

v0.1.0 (2016-03-11)

Collaborator Number Metric

0.6.0 passed this metric

Contributing File Metric

0.6.0 passed this metric

Foodcritic Metric

0.6.0 passed this metric

License Metric

0.6.0 passed this metric

No Binaries Metric

0.6.0 passed this metric

Testing File Metric

0.6.0 passed this metric

Version Tag Metric

0.6.0 passed this metric