ark cookbook do exactly what you want in 1 resource, let's have a look to it:
https://github.com/opscode-cookbooks/ark