Method: Chef::Node#for_json

Defined in:
lib/chef/node.rb

#for_jsonObject



546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
# File 'lib/chef/node.rb', line 546

def for_json
  result = {
    "name" => name,
    "chef_environment" => chef_environment,
    "json_class" => self.class.name,
    "automatic" => attributes.automatic.to_hash,
    "normal" => attributes.normal.to_hash,
    "chef_type" => "node",
    "default" => attributes.combined_default.to_hash,
    "override" => attributes.combined_override.to_hash,
    # Render correctly for run_list items so malformed json does not result
    "run_list" => @primary_runlist.run_list.map(&:to_s),
  }
  # Chef Server rejects node JSON with extra keys; prior to 12.3,
  # "policy_name" and "policy_group" are unknown; after 12.3 they are
  # optional, therefore only including them in the JSON if present
  # maximizes compatibility for most people.
  unless policy_group.nil? && policy_name.nil?
    result["policy_name"] = policy_name
    result["policy_group"] = policy_group
  end
  result
end