1

Ohai,

ist there a way to use LWRP for Chef on AWS OpsWorks? How else would I execute this:

nfs_export "/exports" do
  network '10.0.0.0/8'
  writeable false 
  sync true
  options ['no_root_squash']
end

This is the cookbook this is from:

https://github.com/atomic-penguin/cookbook-nfs

I would like to add an export, but I can't like that. Also, I would like to create an rc.local entry to mount the exports on the nodes - with chef would be ideal for better deployment.

barfurth
  • 155
  • 1
  • 6

1 Answers1

2

You can do this exactly as you would if you were dealing with a normal Chef implementation. If you create a wrapper cookbook, and add a dependency on the NFS cookbook in your cookbook's metadata.rb, the nfs_export resource will be available to use in your wrapper cookbook's default recipe.

To add custom recipes from a Git repository, to an OpsWorks stack, you need to configure the stack to pull the cookbooks in: http://docs.aws.amazon.com/opsworks/latest/userguide/workingcookbook-installingcustom-enable.html

So, for example, you create a git repository with the following structure:

cookbooks -> freshmelon-nfs --> metadata.rb |-> recipes -> default.rb

So that's a cookbooks folder in your repository, where you add a folder for each custom cookbook. The bare bones layout for a cookbook is a metadata.rb in your custom cookbook (freshmelon-nfs in this example) which describes the cookbook, and a recipes folder, which contains one ruby file for each recipe, the default is called default.rb.

As an example metadata.rb

name 'afreshmelon-nfs' maintainer 'Your Name' maintainer_email 'your@email' license 'MIT' description 'NFS Wrapper' long_description 'Configures NFS for aFreshMelon' version '0.1' depends 'nfs'

An example default.rb

nfs_export "/exports" do network '10.0.0.0/8' writeable false sync true options ['no_root_squash'] end

Then you can call afreshmelon-nfs::default in your lifecycle (Setup, Configure, Install) events in the Layer configuration of your OpsWorks stack.

You can also then create a client.rb in your recipes folder, which you can include in the layter configuration for your clients, to mount the export.

mount "/mnt/nfs" do device "yourserver:/exports" fstype "nfs" options "rw" action [:mount, :enable] end

That will add the NFS mount to your fstab, and it will be mounted on boot along with other filesystems.

James Hebden
  • 286
  • 2
  • 7