Runing Chef Client at remote Node


With this article we will write about Chef client and you will be able to up and run with Chef as quickly as possible, and let you run recipes and work with the full power of Chef locally without the need to set up a server, register and grab keys, configure the client, or switch to root.

Here’s the most basic scenario for getting started in local mode:

Setup your project

Install chef and knife-zero

Add specific folder and Gemfile

mkdir -p chef-monit
nano chef-monit/Gemfile

Append to Gemfile

ruby '2.5.1'

source '' do
  gem "chef"
  gem "chef-dk"
  gem "knife-zero"

Install gems with bundle in folder /chef-monit

$ bundle

After Gem installation we will create .chef folder that we’ll use for knife configuration later

$ mkdir .chef

Generate cookbook

Create cookbooks directory

$ mkdir cookbooks

Enter cookbooks directory and generate a cookbook

$ cd cookbooks
$ chef generate cookbook monit

Setup knife

$ nano .chef/knife.rb

Edit knife.rb file like this:

local_mode true
cookbook_path ["./cookbooks", "./site-cookbooks"]
chef_repo_path "./"

Test SSH connectivity

Before node preparation we will test ssh connectivity with server:

Node configuration

Prepare node

We are going to prepare Node:

knife zero bootstrap [email protected]

Wtih bootstarap comamand we are going to install Chef on our remote server.

List Nodes

Use list subcommand to view a list of objects on the Chef server.

knife node list

Show Nodes

Use show subcommand to view the details of one (or more) objects on the Chef server.

knife node show

Running recipe

We run the monit cookbook on remote server by explicitly specifying the cookbook name with --override-runlist option.

knife zero converge "" --ssh-user root --override-runlist "recipe[monit]"

Add recipe to node’s runlist

Sometimes, there is scenario when we don’t need to put –override-runlist, so we execute command like this:

knife node run_list add 'recipe[monit]'