1. Download opscode’s aws cookbook and put it into your own cookbook repo
$ git clone https://github.com/opscode/cookbooks.git opscode-cookbooks $ cp -r opscode-cookbooks/aws my-cookbooks/ $ cd my-cookbooks
2. Create a new cookbook that will utilize the aws cookbook
$ knife cookbook create aws-tests
3. Set the cookbook to have the dependency of the opscode aws cookbook
$ vi my-cookbooks/aws-tests/metadata.rb
maintainer "YOUR_COMPANY_NAME" maintainer_email "YOUR_EMAIL" license "All rights reserved" description "Installs/Configures aws_tests" long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) version "0.0.1" depends "aws"
4. Create your recipe to create and attach a new EBS volume to your ec2 instance
$ vi vi my-cookbooks/aws-tests/recipes/default.rb
# Create and attach your new EBS volume aws_ebs_volume "new_ebs_volume" do aws_access_key "MYAPIKEY" aws_secret_access_key "MYAPIKEYSECRET" size 1 device "/dev/xvdi" action [ :create, :attach ] end
5. Create a filesystem and mount your new volume
# Create your partition and filesystem for ext4 bash "create_filesystem" do user "root" code <<-EOH parted /dev/xvdi mklabel gpt parted /dev/xvdi mkpart logical ext4 1 -1 parted /dev/xvdi set 1 lvm on yes | parted /dev/xvdi mkpart logical ext4 1 -- "-1" mkfs.ext4 /dev/xvdi1 EOH not_if "parted /dev/xvdi1 |grep ext4" end directory "/mnt/test" do owner "root" group "root" mode "0755" recursive true end mount "/mnt/test" do device "/dev/xvdi1" options "rw noatime" fstype "ext4" action [ :enable, :mount ] not_if "cat /proc/mounts |grep /mnt/test" end
6. Add aws and aws_tests recipes to your node
$ knife node edit i-fff4f8c
{ "chef_environment": "_default", "name": "i-fff4f8", "run_list": [ "recipe[aws]", "recipe[aws_tests]" ], "normal": { "tags": [ ], } }
7. Run chef-client on your node
$ chef-client
