问题描述:

I can not find how to mount a device in linux only once with chef. Meaning on the other chef client the resource should not execute because a device there has already been mounted to a specific path.

How can I use chef's idempotency to do this? ...

This is the log stacktrace that I see in the end of chef-client log

[2013-11-06T23:12:28+00:00] ERROR: Running exception handlers

[2013-11-06T23:12:29+00:00] FATAL: Saving node information to /var/chef/cache/failed-run-data.json

[2013-11-06T23:12:29+00:00] ERROR: Exception handlers complete

[2013-11-06T23:12:29+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out

[2013-11-06T23:12:29+00:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: mount[/testpath] (mycookbook::myrecipe line 53) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '32'

STDOUT:

STDERR: mount: /dev/xvdb already mounted or /testpath busy

mount: according to mtab, /dev/xvdb is already mounted on /testpath

---- End output of mount -t auto -o defaults /dev/xvdb /testpath ----

Ran mount -t auto -o defaults /dev/xvdb /testpath returned 32

网友答案:

Use the mount resource:

mount '/testpath' do
  device '/dev/xvdb'
  action [:mount, :enable]
end
网友答案:

so the problem was that I had not put '/' in front of my testpath ... hence the mount resource was not able to identify if /testpath has already been created or not ... Simple syntax mistake with big potential for failure :D ... thank you

网友答案:

Just in case someone lands here mounting nfs (or EFS) volumes on Amazon Linux (ALAMI), the trick is to preface the device path with //. You'll notice that mount output on ALAMI includes that. Note that if you mount at the root of EFS, just a single / is shown and your recipe should match.

Here is a working example:

mount /mnt/mydev do
  device "nfsserver://remotepath/subdir"
  fstype 'nfs'
  action [:mount, :enable]
end

Here is the output of mount on ALAMI:

. . .
us-west-2a.fs-XXXX.efs.us-west-2.amazonaws.com://remotepath/subdir /mnt/mydev nfs defaults 0 2
. . .
网友答案:

first do an :umount and then a :mount action

mount /srv/nfs do device "nfsserver://remotepath/subdir" fstype 'nfs' action [:umount, :disable] end

mount /srv/nfs do device "nfsserver://remotepath/subdir" fstype 'nfs' action [:mount, :enable] end

Done

相关阅读:
Top