Mounting NFS-Shares with Cfengine 3

One often used service is NFS. The ability of mounting a file system over the network is very handy and even I use it regularly in my projects.
Now imagine a scenario where you manage the configuration of your servers with Cfengine 3 and you have a central file server with NFS running on it. You want to mount one NFS share on each of your servers, but of course you are lazy sysadmin. And lazy sysadmin doesn’t connect to a server and types in the mount command.

Let a simple script do the work

body common control {
version => "1.0";
inputs => { "" };
bundlesequence => { "mount_nfs_share" };


bundle agent mount_nfs_share {
"/mnt" mount => nfs("localhost", "/blubb");

Save the file and check if the syntax is correct:

cf-promises -f /var/lib/cfengine3/inputs/

You should not receive any errors, so let’s run cf-agent for executing your new script. I assume that you have a NFS server installed on localhost and created a directory called /blubb. Please adjust the script accordingly if this is not the case for your test setup.

cf-agent -f /var/lib/cfengine3/inputs/

Running the command mount now shows that the NFS share is mounted:

mintbox inputs # mount
/dev/sda1 on / type ext4 (rw,errors=remount-ro,commit=0)
localhost:/blubb on /mnt type nfs (rw,vers=4,addr=,clientaddr=

The script explained
I will not talk about the first section “body common control” since you already know what happens there.
But the second part of is very interesting:

bundle agent mount_nfs_share {
"/mnt" mount => nfs("localhost", "/blubb");

The bundle “mount_nfs_share” contains a promise of the type “storage” which executes the NFS mount. The important parameters are provided within the round brackets.
Well, that’s already it! This code sample shows that Cfengine 3 takes its promise of providing simplicity very serious.

Adding a bonus

Cfengine 3 also has the power to add an entry to the /etc/fstab file. I find this to be very useful, that’s why I will show you how to do that in one of my next blog posts.


By the way, you can download today’s Cfengine3 code snippet here.

One thought on “Mounting NFS-Shares with Cfengine 3

Comments are closed.