Autor: Dmitry Duplyakin
Email: dmitry.duplyakin@colorado.edu
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.
ssh -p 22 dmdu@pc-c220m4-r02-07.wisc.cloudlab.us
sudo su -
root@head:~# ls /chef-repo/cookbooks/
emulab-nfs README.md
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.
...
root@head:~# knife node list
head
node-1
root@head:~# knife cookbook list
root@head:~#
You should see more cookbooks in /chef-repo/cookbooks after this step.
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
root@head:~# ls /chef-repo/roles/
nfs_client.rb nfs_server.rb README.md
root@head:~# knife role from file /chef-repo/roles/*.rb
Updated Role nfs_client!
Updated Role nfs_server!
Roles prescribe which recipes (potentially from different cookbooks) and in which order should run on the nodes, to which the roles are assigned.
root@head:/# knife node run_list add head "role[nfs_server]"
head:
run_list: role[nfs_server]
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
root@head:/chef-repo/cookbooks/nfs/recipes# knife node show head
Node Name: head
FQDN: pc-c220m4-r02-07.wisc.cloudlab.us
Run List: role[nfs_server]
root@head:/# service nfs-kernel-server status
nfsd running
root@head:~# knife node run_list add node-1 "role[nfs_client]"
node-1:
run_list: role[nfs_client]
root@head:~# knife node show node-1
Node Name: node-1
FQDN: pc-c220m4-r04-05.wisc.cloudlab.us
Run List: role[nfs_client]
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
root@head:/# ls /exports/
root@head:/# ssh node-1 "ls /imports"
root@head:/# touch /exports/test
root@head:/# ssh node-1 "ls /imports"
test
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:
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 dmitry.duplyakin@colorado.edu if you have any questions.