Method: Chef::Resource.identity_property

Defined in:
lib/chef/resource.rb

.identity_property(name = nil) ⇒ Symbol

Set the identity of this resource to a particular property.

This drives #identity, which returns data that uniquely refers to a given resource on the given node (in such a way that it can be correlated across Chef runs).

This method is unnecessary when declaring properties with property; properties can be added to identity during declaration with ‘identity: true`.

“‘ruby property :x, identity: true # part of identity property :y # not part of identity “`

Parameters:

  • name (Symbol) (defaults to: nil)

    A list of property names to set as the identity.

Returns:

  • (Symbol)

    The identity property if there is only one; or nil if there are more than one.

Raises:

  • (ArgumentError)

    If no arguments are passed and the resource has more than one identity property.



838
839
840
841
842
843
844
845
# File 'lib/chef/resource.rb', line 838

def self.identity_property(name = nil)
  result = identity_properties(*Array(name))
  if result.size > 1
    raise Chef::Exceptions::MultipleIdentityError, "identity_property cannot be called on an object with more than one identity property (#{result.map(&:name).join(", ")})."
  end

  result.first
end