This demo will walk you through using Chef 12 inside CloudLab's experiment

Autor: Dmitry Duplyakin


Date: 09/14/2015

Here we use artifacts from the Emulab's Chef repository, which reduce the number of manual steps. If you want to see how to build things from scratch, use the this demo.


  • Chef12Slice Profile 
    • ​Profile with Chef Server, Workstation, and Clients. See more information in the profile description
  • Emulab's Chef Repository
    • ​Repository of recommended (carefully developed and well tested) cookbooks. It will be cloned onto the head node on the instance of the profile
  • Chef Supermarket (collection of community developed cookbooks)
    • We will download and use the NFS cookbook in this demo


Launching an Experiment

  • Instantiate Chef12Slice 
  • Wait until it says "Your experiment is ready"

Getting Started

  • After a few minutes, when Chef is fully configured, you should get an email: 
  • After receiving this email, log into the head node
    • E.g., 
  • Switch to root:
ssh -p 22
sudo su - 

Getting Started with knife

  • There are two nodes in the Chef environment and no cookbooks by default
root@head:~# ls /chef-repo/cookbooks/
root@head:~# cat /chef-repo/cookbooks/emulab-nfs/metadata.rb 
name             'emulab-nfs'
depends 'nfs'

root@head:~# knife cookbook site install nfs
Installing nfs to /chef-repo/cookbooks
Uncompressing nfs version 2.2.5.
  • You should see some cookbooks downloaded from the Emulab's repostory
root@head:~# knife node list
root@head:~# knife cookbook list

  • Notice that emulab-nfs cookbook depends on nfs. Install nfs and its dependencies from Chef Supermarket

You should see more cookbooks in /chef-repo/cookbooks after this step.

Uploading Cookbooks

root@head:~# knife cookbook upload -a
Uploading emulab-nfs   [0.1.0]
Uploading line         [0.6.2]
Uploading nfs          [2.2.5]
Uploading ohai         [2.0.1]
Uploading sysctl       [0.6.2]
Uploaded all cookbooks.
root@head:~# knife cookbook list
emulab-nfs   0.1.0
line         0.6.2
nfs          2.2.5
ohai         2.0.1
sysctl       0.6.2
  • Upload all cookbooks to Chef server (on head) in order to make them available to the clients and check

Uploading Roles

root@head:~# ls /chef-repo/roles/
nfs_client.rb  nfs_server.rb
  • Along with the cookbooks, your copy of the Emulab's Chef repository contains some roles
root@head:~# knife role from file /chef-repo/roles/*.rb
Updated Role nfs_client!
Updated Role nfs_server!
  • Just like cookbooks, roles need to be uploaded to the server in order to become useable

Roles prescribe which recipes (potentially from different cookbooks) and in which order should run on the nodes, to which the roles are assigned.

Configuring NFS Server

root@head:/# knife node run_list add head "role[nfs_server]"
  run_list: role[nfs_server]
  • Assign nfs_server role to head
  • Check what is assigned to run on head
root@head:/# chef-client 
Starting Chef Client, version 12.0.3
resolving cookbooks for run list: ["emulab-nfs::export"]
Synchronizing Cookbooks:
Running handlers complete
Chef Client finished, 14/22 resources updated in 9.592334135 seconds
  • Trigger the configuration process locally, on head (in Chef terms: converge the node)
root@head:/chef-repo/cookbooks/nfs/recipes# knife node show head
Node Name:   head
Run List:    role[nfs_server] 
root@head:/# service nfs-kernel-server status
nfsd running
  • NFS server is running now:

Configuring NFS Client

root@head:~# knife node run_list add node-1 "role[nfs_client]"
  run_list: role[nfs_client]
root@head:~# knife node show node-1
Node Name:   node-1
Run List:    role[nfs_client]
  • Check what is assigned to run on node-1
  • Assign nfs cookbooks to node-1
root@head:~# ssh node-1 chef-client 
[2015-09-14T12:44:11-05:00] INFO: Forking chef instance to converge...
[2015-09-14T12:44:11-05:00] INFO: *** Chef 12.4.1 ***
[2015-09-14T12:44:13-05:00] INFO: Run List is [role[nfs_client]]
[2015-09-14T12:44:32-05:00] INFO: Report handlers complete
[2015-09-14T12:44:32-05:00] INFO: Chef Run complete in 19.37269083 seconds
  • Converge node-1 via ssh

Mounting and Testing

root@head:/# ls /exports/
root@head:/# ssh node-1 "ls /imports"
root@head:/# touch /exports/test
root@head:/# ssh node-1 "ls /imports"
  • Testing NFS export/mount - add a file on head and see it on node-1 

After both head and node-1 converge to their roles, /exports from head should be exported and mounted on node-1 under /imports.


Keep in mind that configuration options (in Chef terms, attributes), which define which directory is exported and where it is mounted, are set in the roles nfs_server.rb and nfs_client.rb in /chef-repo/roles. If you change those files, they should be uploaded to the server again.



​In this demo we:

  • Used Chef12Slice with Chef Server, Workstation (knife utility), and Clients (on head and node-1
  • Downloaded and installed a community cookbook (nfs) and its dependecies
  • Uploaded local cookbooks and roles (cloned from the Emulab's Chef repository) to Chef Server 
  • Assigned roles to nodes
  • Converged two nodes (head and node-1 via ssh) to install and configure both server and client sides of NFS
  • Tested the NFS installation
  • Performed all these steps, essentially without leaving the head node


Final remark: 

If you want to see a demo with more manual steps, where we build recipes and roles from scratch instead of cloning them, please follow this link


Email if you have any questions. 


Demo of Chef 12 inside CloudLab's Experiment

By Dmitry Duplyakin

Demo of Chef 12 inside CloudLab's Experiment

Demo of Chef 12 inside CloudLab's Experiment with the streamlined workflow (leverages the Emulab's Chef repo)

  • 886
Loading comments...

More from Dmitry Duplyakin