Created
January 13, 2014 20:54
-
-
Save xofer/8407957 to your computer and use it in GitHub Desktop.
format and mount an EBS volume in Chef
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby_block "wait for #{device_id}" do | |
block do | |
count = 1 | |
loop do | |
if File.blockdev?(device_id) or count >= 10 | |
break | |
else | |
Chef::Log.info("device #{device_id} not ready - sleeping 10s") | |
sleep 10 | |
count += 1 | |
end | |
end | |
end | |
end | |
# create file system | |
execute "mkfs #{device_id}" do | |
command "mkfs -t ext4 -m 0.25 #{device_id}" | |
# only if it's not mounted already | |
not_if "grep -qs #{mount_point} /proc/mounts" | |
end | |
# mount | |
directory mount_point do | |
mode "0775" | |
owner "cogtree" | |
group "cogtree" | |
recursive true | |
action :create | |
end | |
mount mount_point do | |
device device_id | |
fstype 'ext4' | |
options 'rw,noatime,nobootwait' | |
action [:enable, :mount] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment