简体   繁体   English

如何在Chef Opscode中使用idempotency来执行一次mount资源?

[英]How can I use idempotency in Chef Opscode to execute a mount resource only once?

I can not find how to mount a device in linux only once with chef. 我找不到如何使用厨师在linux上安装一次设备。 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 这是我在chef-client日志末尾看到的日志堆栈跟踪

[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资源:

mount '/testpath' do
  device '/dev/xvdb'
  action [:mount, :enable]
end

所以问题是我没有把'/'放在我的测试路径前...因此mount资源无法识别是否已经创建了/ testpath ...简单的语法错误, 很有可能失败: D ...谢谢

Just in case someone lands here mounting nfs (or EFS ) volumes on Amazon Linux (ALAMI), the trick is to preface the device path with // . 如果有人在这里登陆亚马逊Linux(ALAMI)上安装nfs(或EFS )卷,诀窍是在设备路径前面加上// You'll notice that mount output on ALAMI includes that. 你会注意到ALAMI上的mount输出包含了这一点。 Note that if you mount at the root of EFS, just a single / is shown and your recipe should match. 请注意,如果您安装在EFS的根目录下,则只显示一个/ ,并且您的配方应该匹配。

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: 这是ALAMI上mount的输出:

. . .
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 先做一个:umount然后一个:mount动作

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 完成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM