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

Autor: Dmitry Duplyakin

Email: dmitry.duplyakin@colorado.edu

Date: 09/14/2015

Here we use cookbooks from Chef Supermarket and attempt to do the rest manually. If you want to see a demo of the more streamlined process, use the this demo.

Resources

  • 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 dmdu@pc-c220m4-r02-07.wisc.cloudlab.us
sudo su - 

Empty the Repository

  • There might be some cookbooks that were cloned from the Emulab's Chef repository. In this demo, we don't need to use them, therefore you should delete them in order to avoid potential conflicts (keep README.md though).
root@head:~# cd /chef-repo/cookbooks/
root@head:~# ls 
emulab-nfs  README.md
root@head:/chef-repo# ls | grep -v README.md | xargs rm -rf
root@head:~# ls
README.md
  • Do the same with the cloned roles in /chef-repo/roles
root@head:~# cd /chef-repo/roles/
root@head:~# ls 
nfs_server.rb   nfs_client.rb   README.md
root@head:/chef-repo# ls | grep -v README.md | xargs rm -rf
root@head:~# ls
README.md

Getting Started with knife

  • There are two nodes in the Chef environment and no cookbooks by default
root@head:~# knife cookbook site install nfs
Installing nfs to /chef-repo/cookbooks
Creating pristine copy branch chef-vendor-nfs
Cookbook saved: /chef-repo/cookbooks/nfs.tar.gz
Uncompressing nfs version 2.2.5.
...
root@head:~# knife cookbook upload -a
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
line         0.6.2
nfs          2.2.5
ohai         2.0.1
sysctl       0.6.2
  • Get the NFS cookbook (and its dependencies) from Chef Supermarket
  • Upload all cookbooks to Chef server (on head) and check

All cookbooks are in /chef-repo/cookbooks/. NFS cookbook: https://supermarket.chef.io/cookbooks/nfs

root@head:~# knife node list
head
node-1
root@head:~# knife cookbook list

root@head:~#

Configuring NFS Server: Role

  • Create a role for NFS server and upload it to the server 
root@head:~# cd /chef-repo/roles/
root@head:/chef-repo/roles# vi nfs_server.rb

<COPY AND PASTE THE FOLLOWING>
name "nfs_server"
description "Role applied to the system that should be an NFS server."
override_attributes(
  "nfs" => {
    "packages" => [ "portmap", "nfs-common", "nfs-kernel-server" ],
    "port" => {
      "statd" => 32765,
      "statd_out" => 32766,
      "mountd" => 32767,
      "lockd" => 32768
    }
  }
)
run_list [ "nfs::server" ]
<SAVE AND EXIT>

root@head:/chef-repo/roles# knife role from file nfs_server.rb 
Updated Role nfs_server!
root@head:/# knife node run_list add head "role[nfs_server]"
head:
  run_list: role[nfs_server]
  • Assign this role to head

Configuring NFS Server: Recipe

  • Create a recipe for exporting /exports from head and upload the updated nfs cookbook to the server (to make the new recipe available)
root@head:/# knife node run_list add head "recipe[nfs::export]"
head:
  run_list:
    role[nfs_server]
    recipe[nfs::export]
  • Assign this recipe to head
root@head:/chef-repo/roles# cd /chef-repo/cookbooks/nfs/recipes
root@head:/chef-repo/cookbooks/nfs/recipes# vi export.rb

<COPY AND PASTE, UPDATE THE NETWORK ADDRESS IF NECESSARY>
# Cookbook Name:: nfs
# Recipe:: export
directory '/exports' do
  action :create
end
nfs_export "/exports" do
  network '10.0.0.0/8'
  writeable false
  sync true
  options ['no_root_squash']
end
<SAVE AND EXIT>

root@head:/chef-repo/cookbooks/nfs/recipes# knife cookbook upload nfs
Uploading nfs            [2.2.5]
Uploaded 1 cookbook.

Configuring NFS Server: Run

  • Check what is assigned to run on head
root@head:/# chef-client 
Starting Chef Client, version 12.0.3
resolving cookbooks for run list: ["nfs::server", "nfs::export"]
Synchronizing Cookbooks:
  - nfs
  - line
  - sysctl
  - ohai
Compiling Cookbooks...
...

Running handlers:
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
Environment: _default
FQDN:        pc-c220m4-r02-07.wisc.cloudlab.us
IP:          128.104.222.37
Run List:    role[nfs_server], recipe[nfs::export]
Platform:    ubuntu 14.04      
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 "recipe[nfs]"
node-1:
  run_list: recipe[nfs]

Typically, this command is used in the form: knife node run_list add <node> "recipe[<cookbook>::<specific recipe>]". If only the name of the cookbook is specified in square brackets like in the example above, the default recipe is used (in this particular case, /chef-repo/cookbooks/nfs/recipes/default.rb

root@head:/# knife node show node-1
Node Name:   node-1
Environment: _default
FQDN:        pc-c220m4-r02-15.wisc.cloudlab.us
IP:          128.104.222.45
Run List:    recipe[nfs]
Platform:    ubuntu 14.04
  • Check what is assigned to run on node-1
  • Assign nfs cookbooks to node-1
root@head:/# ssh node-1 chef-client
[2015-09-09T10:43:14-05:00] INFO: Forking chef instance to converge...
[2015-09-09T10:43:14-05:00] INFO: *** Chef 12.4.1 ***
[2015-09-09T10:43:14-05:00] INFO: Chef-client pid: 4587
[2015-09-09T10:43:15-05:00] INFO: Run List is [recipe[nfs]]
...
  • Converge node-1 via ssh

Mounting and Testing

root@head:/# ssh node-1 "mkdir /imports"
root@head:/# ssh node-1 "mount head:/exports /imports"
  • Mount /exports from head on node-1 under /imports (via ssh) 

These commands can form a client-side recipe in the nfs cookbook if such organization if preferred.

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

Summary

​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)
  • Created a role (nfs_server) and assigned it to a node
  • Created a recipe (nfs::export) and assigned it to a node
  • Converged two nodes (head and node-1 via ssh) to install and configure both server and client sides for NFS
  • Tested the NFS installation
  • Performed all these steps essentially without leaving the head node

 

Final remark: 

The Emulab's Chef Repository provides the cookbooks and roles that simplify the installation and configuration process for NFS. See the emulab-nfs cookbook in the repo. If you want to see a demo of the streamlined process, please follow this link

 

Email dmitry.duplyakin@colorado.edu 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 that shows manual steps

  • 821
Loading comments...

More from Dmitry Duplyakin