每次厨师 - 客户端运行时,厨师创建/服务

时间:2014-08-19 20:57:57

标签: chef

我有一个配方,可以在运行chef-client时创建/服务并安装它。但是,即使厨师已经创建并将其添加到fstab,也会挂载/服务。我以为厨师不会这样做。

#mkdir /service
directory node['storm-prep']['service']['dir'] do
  owner "root"
  group "root"
  mode 00755
  action :create
 recursive true
end

#Create /service
lvm_logical_volume node['storm-prep']['service']['name'] do
    group node['storm-prep']['volume-group']['name']
    size node['storm-prep']['service']['size']
    filesystem node['storm-prep']['filesystem']['type']
    mount_point #{node['storm-prep']['service']['dir']}
    action [:create]
end

#mount /service and add to fstab
mount node['storm-prep']['service']['dir'] do
    device node['storm-prep']['service']['device']
    fstype node['storm-prep']['filesystem']['type']
end

厨师 - 客户端错误结束

014-08-19T16:19:31-05:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: execute[mount /service and add to fstab] (storm-prep-cookbook::default line 41) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '32'
---- Begin output of echo '/dev/mapper/vg00-servicelv00  /service       ext4 defaults        0   0' >> /etc/fstab && mount /service ----
STDOUT: 
STDERR: mount: /dev/mapper/vg00-servicelv00 already mounted or /service busy
mount: according to mtab, /dev/mapper/vg00-servicelv00 is already mounted on /service
---- End output of echo '/dev/mapper/vg00-servicelv00  /service       ext4 defaults        0   0' >> /etc/fstab && mount /service ----
Ran echo '/dev/mapper/vg00-servicelv00  /service       ext4 defaults        0   0' >> /etc/fstab && mount /service returned 32

2 个答案:

答案 0 :(得分:2)

您可以使用所谓的guardnot_if。像这样:

mount node['storm-prep']['service']['dir'] do
    device node['storm-prep']['service']['device']
    fstype node['storm-prep']['filesystem']['type']
    # Don't execute the action if "/service" exists
    not_if "grep '/service' /etc/fstab"
end

答案 1 :(得分:0)

修复

#Create /service

mount_point #{node['storm-prep']['service']['dir']}

需要

#Create /service

mount_point node['storm-prep']['service']['dir']

整个#mount部分可以删除

根本原因是LVM食谱中存在大量问题和错误代码