Skip to end of metadata
Go to start of metadata


Shef: The Chef REPL

Shef is a way to run chef in an Interactive Ruby (IRb) session. Shef currently supports recipe and attribute file syntax, as well as interactive debugging features.

Run Modes

Shef has three run modes:

  • Standalone
    No cookbooks are loaded, and the run list is empty. This mode is the default.
  • Solo
    Shef acts as a chef-solo client. It attempts to load chef-solo's configuration file and JSON attributes. If the JSON attributes set a run list, it will be honored. Cookbooks will be loaded in the same way that chef-solo loads them. Solo mode is activated with the -s or --solo command line option, and JSON attributes are specified in the same way as for chef-solo, with -j /path/to/chef-solo.json.
  • Client
    Shef acts as a chef-client. During startup, it reads the chef client configuration file and contacts the server to get attributes and cookbooks. The run list will be set in the same way as normal chef client runs. Client mode is activated with the -z or --client options. You can also specify the configuration file with -c CONFIG and the server URL with -S SERVER_URL.

For more detail on the Chef REPL, see Shef.

Getting Started

First, let's start Shef in "standalone" mode, so it doesn't inherit any other configuration. We run this with sudo so we can install a simple package in this example.

The next step is to enter recipe mode, so we can create actual resources that Chef will manage. We also turn off echoing return values to keep the terminal output clean.

Now we can start writing Resources directly into the console, and then run Chef to have them created on the system.

If we look at the local filesystem, we'll see this file has been created:

Neat!

Now let's take a look at how we can use a node attribute. Here, we'll set a node attribute, and then simply display it to the output log.

We first enter attributes editing mode, putting shef into the context of a node's attribute space. We set the attribute value, then we enter recipe mode to create a log resource.

Now let's put the content of this attribute into a file.

If we look at this file, we see it contains the string from the attribute we set earlier.

The next example will install a package on the local system.

The next example will install three gems that are optional for use with Knife sub-commands (fog, net-ssh-multi and highline)

Uses of Shef

Onward to Shef for more details, including its use for managing the Chef Server, debugging Recipes, and more.





Fast Start Guide


Managing Chef



Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.