A node is any physical, virtual, or cloud machine that is configured to be maintained by a chef-client.
The knife node subcommand is used to manage the nodes that exist on a Chef server.
Note
Review the list of common options available to this (and all) Knife subcommands and plugins.
The bulk delete argument is used to delete one or more nodes that match a pattern defined by a regular expression. The regular expression must be within quotes and not be surrounded by forward slashes (/).
This command does not have any specific options.
The following examples show how to use this Knife subcommand:
Bulk delete nodes
Use a regular expression to define the pattern used to bulk delete nodes:
$ knife node bulk delete "^[0-9]{3}$"
Type Y to confirm a deletion.
The create argument is used to add a node to the Chef server. Node data is stored as JSON on the Chef server.
This command does not have any specific options.
The following examples show how to use this Knife subcommand:
Create a node
To add a node, enter:
$ knife node create node1
In the $EDITOR enter the node data in JSON:
## sample:
{
"normal": {
},
"name": "foobar",
"override": {
},
"default": {
},
"json_class": "Chef::Node",
"automatic": {
},
"run_list": [
"recipe[zsh]",
"role[webserver]"
],
"chef_type": "node"
}
When finished, save it.
The delete argument is used to delete a node from the Chef server.
Note
Deleting a node will not delete any corresponding API clients.
This command does not have any specific options.
The following examples show how to use this Knife subcommand:
Delete a node
$ knife node delete node_name
The edit argument is used to edit the details of a node on a Chef server. Node data is stored as JSON on the Chef server.
This argument has the following options:
The following examples show how to use this Knife subcommand:
Edit a node
To edit the data for a node named “node1”, enter:
$ knife node edit node1 -a
Update the role data in JSON:
## sample:
{
"normal": {
},
"name": "node1",
"override": {
},
"default": {
},
"json_class": "Chef::Node",
"automatic": {
},
"run_list": [
"recipe[devops]",
"role[webserver]"
],
"chef_type": "node"
}
When finished, save it.
The from file argument is used to create a node using existing node data as a template.
This command does not have any specific options.
The following examples show how to use this Knife subcommand:
Create a node using a JSON file
To add a node using data contained in a JSON file:
$ knife node from file "path to JSON file"
The list argument is used to view all of the nodes that exist on a Chef server.
This argument has the following options:
The following examples show how to use this Knife subcommand:
View a list of nodes
To verify the list of nodes that are registered with the Chef server, enter:
$ knife node list
to return something similar to:
i-12345678
rs-123456
A run-list is an ordered list of roles and/or recipes that are run in an exact order. A run-list is always specific to the node on which it runs, though it is possible for many nodes to have run-lists that are similar or even identical. The items within a run-list are maintained using Knife and are uploaded to the Chef server and stored as part of the node object for each node. The chef-client always configures a node in the exact order specified by its run-list and will never run the same recipe twice.
The run_list add argument is used to add run list items (roles or recipes) to a node.
A run-list must be in one of the following formats: fully qualified, cookbook, or default. Both roles and recipes must be in quotes, for example:
'role[ROLE_NAME]'
or
'recipe[COOKBOOK::RECIPE_NAME]'
Use a comma to separate roles and recipes when adding more than one item the run-list:
'recipe[COOKBOOK::RECIPE_NAME],COOKBOOK::RECIPE_NAME,role[ROLE_NAME]'
This argument has the following syntax:
$ knife node run_list add NODE_NAME RUN_LIST_ITEM (options)
This argument has the following options:
The following examples show how to use this Knife subcommand:
Add a role
To add a role to a run list, enter:
$ knife node run_list add node 'role[ROLE_NAME]'
Add roles and recipes
To add roles and recipes to a run list, enter:
$ knife node run_list add node 'recipe[COOKBOOK::RECIPE_NAME],recipe[COOKBOOK::RECIPE_NAME],role[ROLE_NAME]'
Add a recipe with a FQDN
To add a recipe to a run list using the fully qualified format, enter:
$ knife node run_list add node 'recipe[COOKBOOK::RECIPE_NAME]'
Add a recipe with a cookbook
To add a recipe to a run list using the cookbook format, enter:
$ knife node run_list add node 'COOKBOOK::RECIPE_NAME'
Add the default recipe
To add the default recipe of a cookbook to a run list, enter:
$ knife node run_list add node 'COOKBOOK'
The run_list remove argument is used to remove run list items (roles or recipes) from a node. A recipe must be in one of the following formats: fully qualified, cookbook, or default. Both roles and recipes must be in quotes, for example: 'role[ROLE_NAME]' or 'recipe[COOKBOOK::RECIPE_NAME]'. Use a comma to separate roles and recipes when removing more than one, like this: 'recipe[COOKBOOK::RECIPE_NAME],COOKBOOK::RECIPE_NAME,role[ROLE_NAME]'.
This argument has the following syntax:
$ knife node run_list remove NODE_NAME RUN_LIST_ITEM
This command does not have any specific options.
The following examples show how to use this Knife subcommand:
Remove a role
To remove a role from a run list, enter:
$ knife node run_list remove node 'role[ROLE_NAME]'
Remove a run-list
To remove a recipe from a run list using the fully qualified format, enter:
$ knife node run_list remove node 'recipe[COOKBOOK::RECIPE_NAME]'
The show argument is used to display information about a node.
This argument has the following options:
The following examples show how to use this Knife subcommand:
Show all data about nodes
To view all data for a node named “build”, enter:
$ knife node show build
to return:
Node Name: build
Environment: _default
FQDN:
IP:
Run List:
Roles:
Recipes:
Platform:
Show basic information about nodes
To show basic information about a node, truncated and nicely formatted:
knife node show <node_name>
Show all data about nodes, truncated
To show all information about a node, nicely formatted:
knife node show -l <node_name>
Show attributes
To list a single node attribute:
knife node show <node_name> -a <attribute_name>
where <attribute_name> is something like kernel or platform. (This doesn’t work for nested attributes like node[kernel][machine] because knife node show doesn’t understand nested attributes.)
Show the FQDN
To view the FQDN for a node named “i-12345678”, enter:
$ knife node show i-12345678 -a fqdn
to return:
fqdn: ip-10-251-75-20.ec2.internal
Show a run-list
To view the run list for a node named “dev”, enter:
$ knife node show dev -r
Show as JSON data
To view information in JSON format, use the -F common option as part of the command like this:
$ knife role show devops -F json
Other formats available include text, yaml, and pp.
Show as raw JSON data
To view node information in raw JSON, use the -l or --long option:
knife node show -l -F json <node_name>
and/or:
knife node show -l --format=json <node_name>