Fetching contributors…
Cannot retrieve contributors at this time
88 lines (60 sloc) 2.67 KB


Use the machine_name resource to manage a machine's name. In theory, the machine_name resource should yield the same results that setting the Computer Name field in System Preferences would.

As defined by the scutil manual, an individual macOS system has three different types of names managed by scutil: ComputerName, LocalHostName, and HostName.

A dns_domain property can be optionally specified. This will be tacked on to the end of the specified hostname property to form a fully-qualified domain name that the system HostName will be set to.

When the state of a machine_name resource changes, an ohai resource is notified to reload; this is so that all name changes are reflected and immediately available via the node's normal attributes. Additionally, regardless of the chosen ComputerName, both HostName and LocalHostName will be formatted to adhere to RFC 1034.


A machine_name resource block manages a machine's name. The simplest use of the machine_name resource is:

machine_name "Johnny's MacBookPro"

which would set:

  • ComputerName to Johnny's MacBookPro
  • LocalHostName to Johnnys-MacBookPro
  • HostName to Johnnys-MacBookPro

The full syntax for all of the properties that are available to the machine_name resource is:

machine_name 'description' do
  computer_name               String # defaults to 'hostname' if not specified
  local_hostname              String # defaults to 'hostname' if not specified
  hostname                    String # defaults to the 'name' property if not specified
  dns_domain                  String



      Ruby type: String

      The user-friendly name for the system.


      Ruby type: String

      The local (Bonjour) host name.


      Ruby Type: String

      The name associated with hostname(1) and gethostname(3).


      Ruby type: String

      Domain Name System domain name.


Set HostName, LocalHostName, and ComputerName to different values

machine_name 'set computer/hostname' do
  hostname 'johnnys-macpro'
  computer_name "Johnny's MacPro"
  local_hostname "Johnnys-MacPro"
  dns_domain ''