Chef - How knife connects to node

how knife-solo and knife-zero connect to the node when bootstrapping and cooking.



it’s possible to connect to node using:

knife-solo creates new node file in nodes/ after bootstrapping the node.

node name (as listed in knife node list -z and used later for cooking) and node file name (file in nodes/) are the same and they depend on what was used when bootstrapping the node:


when using knife-solo and chef-solo there is no chef server where information about nodes might be stored. that is why knife connects to node in the same way as described above for bootstrapping.

cooking itself:

it’s possible to specify alternate node file whose name differs from domain or IP address used to connect to the node:

$ knife solo cook tap349 nodes/tap349-2.json



same as for knife-solo except that it’s possible to specify node name explicitly with --node-name option when bootstrapping the node - node and node file will both have specified name.


after bootstrapping node is added to the list of nodes on chef-zero server (use knife zero show tap349 -z to view node information).

information about the node (such as FQDN, IP, Platform, etc.) is retrieved from automatic attributes collected by ohai during bootstrapping (corresponding attributes: fqdn, ipaddress, platform, etc.).

when cooking we search for node on chef-zero server using node name assigned to the node during bootstrapping:

$ knife zero converge 'name:tap349' -z

when cooking knife-zero tries to connect to node using FQDN by default (node’s FQDN is read from node information on chef-zero server) - consequently changing host, domain or IP address in either SSH config or node file itself has no effect on cooking.

it’s possible to make knife-zero use IP instead of FQDN for opening the connection to the node by specifying -a, --attribute option (doc):

The attribute to use for opening the connection

$ knife zero converge 'name:tap349' -a ipaddress -z

or set attribute permanently in knife.rb:

knife[:attribute] = 'ipaddress'

BTW after setting specific attribute for knife only this attribute will be shown in node information with knife node show tap349 -z command. also it’s possible to specify multiple attributes for knife in knife[:attribute] option using array ['ipaddress', 'fqdn']: only specified attributes will be shown in node information but it will break knife zero converge command as it expects a string - not array:

$ knife zero converge 'name:tap349' -z
Exception: NoMethodError: undefined method `split' for ["ipaddress"]:Array

on the other hand when searching for nodes the value of knife[:attribute] option must be set to array:

$ knife search node "name:tap349" -F json -z
Exception: NoMethodError: undefined method `each' for "ipaddress":String

it’s all really confusing :) the point might be that knife-zero is a 3rd-party gem not officially supported by chef and it hasn’t been tested with all available knife options.