Autor: Dmitry Duplyakin
Email: dmitry.duplyakin@colorado.edu
Date: 09/09/2015
ssh -p 22 dmdu@pc-c220m4-r02-07.wisc.cloudlab.us
sudo su -
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
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:~#
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]
root@head:/# knife node run_list add head "recipe[nfs::export]"
head:
run_list:
role[nfs_server]
recipe[nfs::export]
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.
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
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
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
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]]
...
root@head:/# ssh node-1 "mkdir /imports"
root@head:/# ssh node-1 "mount head:/exports /imports"
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
In this demo we:
Final remark:
Currently the Emulab's Chef repo (https://github.com/emulab/chef-repo) is empty. In the future, when the repo is populated, we can reduce the number of manual steps (e.g., avoid creating roles and recipes by hand - they will be cloned along with other artifacts in the repo). Then, the basic workflow will go like this: clone the repo, assign roles/recipes to nodes, and converge nodes. All these steps have been shown in this demo.
Email dmitry.duplyakin@colorado.edu if you have any questions.