Reputation: 739
I have a recipe that will create /service and mount it when chef-client is ran. However, chef will mount /service even though it's already created and add it to fstab. I thought chef would know not to do this.
#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
End of chef-client error
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
Upvotes: 1
Views: 209
Reputation: 739
The fix is
#Create /service
mount_point #{node['storm-prep']['service']['dir']}
needs to be
#Create /service
mount_point node['storm-prep']['service']['dir']
And the whole #mount section can be removed
The root cause is the LVM cookbook having tons of issues and bad code
Upvotes: 0
Reputation: 158210
You can use a so called guard
: not_if
. Like this:
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
Upvotes: 2