Skip to content

Instantly share code, notes, and snippets.

Created May 1, 2013 14:02
Show Gist options
  • Save anonymous/8eaaaaf33898ebd80148 to your computer and use it in GitHub Desktop.
Save anonymous/8eaaaaf33898ebd80148 to your computer and use it in GitHub Desktop.
# Define to do all the things you normally want with an
# EBS volume: create, attach, format, mount.
# This is safely idempotent as it won't create a volume
# if the device exists, and won't create a filesystem if
# the system can recognize it as an XFS filesystem or an
# ext{2,3,4} filesystem.
define :mydrive_ebs, :size => 50, :device => '/dev/xvdo', :options => 'rw' do
# 10.xx kernels use sd* to refer to Xen block devices.
# 12.xx kernels use xvd*
# Regardless, Amazon use sd*...so substitute where necessary.
if node[:platform_version] == '10.10'
params[:device] = params[:device].sub('xvd', 'sd')
end
aws_ebs_volume params[:name] do
aws_access_key node[:mydrive][:aws_access_key]
aws_secret_access_key node[:mydrive][:aws_secret_access_key]
size params[:size]
device params[:device].sub('xvd', 'sd') # Mmm, thanks for that, Xen team
action [:create, :attach]
not_if { File.exist? params[:device] }
end
package "xfsprogs"
execute "create-#{params[:name]}-xfs-filesystem" do
command "mkfs.xfs #{params[:device]}"
not_if "xfs_admin -l #{params[:device]} || e2label #{params[:device]}"
end
directory params[:mountpoint]
mount params[:mountpoint] do
device params[:device]
fstype "xfs"
options params[:options]
action [:mount, :enable]
end
aws_resource_tag 'set_tag' do
aws_access_key node[:mydrive][:aws_access_key]
aws_secret_access_key node[:mydrive][:aws_secret_access_key]
resource_id [ "#{node['aws']['ebs_volume']["#{params[:name]}"]['volume_id']}" ]
tags({"Name" => "#{node['name']}", "do not delete" => "", "Environment" => node.chef_environment})
subscribes :run, resources(execute: "create-#{params[:name]}-xfs-filesystem")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment