We have a Chef recipe with a couple resource blocks. The first resource block is in bash and gets the value of the UUID of a logical volume and stores into variable $uuid.
# Get UUID value
bash 'get uuid' do
cwd "/"
code <<-EOH
uuid=$(blkid -o value -s UUID /dev/vg_volgroup/lv_logicalvolume)
EOH
end
We need to pass the variable $uuid to our second resource block:
# Mount directory, format, update fstab
mount node['mount_dir'] do
dump 1
pass 2
device #{uuid}
device_type :uuid
fstype node['fstype']
options node['options']
action [ :mount, :enable]
end
Unfortunately, this is not working. The value of $uuid is not getting passed into the second resource block for device.
Is there a more proper way to reference $uuid from within the second resource block? Is what I’m asking even possible?
You could get the uuid from ohai. Try running “ohai filesystem2/by_device” from command line to see if you can get what you need. Then you could use something like node[‘filesystem2’][‘by_device’][‘YOUR_DEVICE’][‘uuid’] ohai attribute in your recipe.
Setting uuid in ruby like you do above is not working. Not able to get the device, or device does not exist. Maybe the syntax needs fixing?
The “ohai filesystem2/by_device” command does work, but trying to use the ohai attribute in my recipe is not working yet. I must not be constructing the attribute properly.