1

I'm just getting started with Chef and have gone through the tutorials on their site, however everything seems to assume you'd be configuring a chef server etc. for the deploy

I'm currently in the process of setting up a site on AWS opsworks so I wanted to use Chef for the configuration and installing dependencies. As such I believe I just supply a path to my cookbook. Now before I launch into Opsworks I was trying to create my cookbook on an ubuntu VM and test that it installs everything correctly.

I know that for a single script I can use the chef-client file.rb command to run it, but how can I run a cookbook on a local machine in a similar fashion? I've tried

chef-client chef-repo But this errors, even when using the basic 'motd' example

I've tried searching for examples, but as I say I'm new to Chef so I'm not sure if the terminology I'm searching for is correct.

Is this even the correct approach for developing for Opsworks with Chef?

Thanks

TommyBs
  • 9,354
  • 4
  • 34
  • 65
  • Is that a command or a new dependency? I do actually want to build my cookbook locally as well to actually run it, not just test. – TommyBs Feb 14 '16 at 12:25
  • 1
    I second that. Test-kitchen allows you to build, run and test your cookbook locally quite easily. Ideally you'd be writing your cookbook in a test-first approach, but that's not a requirement for using it. Have a look at http://kitchen.ci – cassianoleal Feb 15 '16 at 13:44
  • Test Kitchen is not directly an option for OpsWorks users due to Amazon's custom run-time data systems. – coderanger Feb 16 '16 at 00:26

2 Answers2

2

OpsWorks is a hosted product of Amazon Web Services, there is no local development environment for it. You would have to create an EC2 instance and use it for testing et al. Unfortunately Amazon has rejected most of the Chef ecosystem tools, so while OpsWorks is powered by Chef it is also a very different beast.

For normal Chef outside of OpsWorks you would use Test Kitchen for this kind of thing, it handles creating a test VM using Vagrant or another system (docker, ec2, etc), installing Chef, running your cookbook(s), and then running some tests.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • I know opsworks doesn't have a local development environment as such, but I was just running my cookbook locally to make sure it was at least installing/configuring what I hoped it would. I've actually managed to get this working using a run list with the cookbook name as the only parameter. Though it only ever seems to use the default recipe and not any of the included ones – TommyBs Feb 15 '16 at 08:01
  • If your cookbook is using any data bags filled in by OpsWorks you literally can't test it outside of OpsWorks unless you fake that data. – coderanger Feb 16 '16 at 00:24
0

Check : How are people testing opsworks cookbooks?

Amazon doc said :

Packaging Cookbook Dependencies Locally

You can use Berkshelf to package your cookbook dependencies locally, upload the package to Amazon S3, and modify your stack to use the package on Amazon S3 as a cookbook source. Content delivered to Amazon S3 buckets might contain customer content. For more information about removing sensitive data, see How Do I Empty an S3 Bucket? or How Do I Delete an S3 Bucket?.

The following walkthroughs describe how to pre-package your cookbooks and their dependencies into a .zip file, and then use the .zip file as your cookbook source for Linux instances in AWS OpsWorks Stacks. The first walkthrough describes how to package one cookbook. The second walkthrough describes how to package multiple cookbooks.

Before you begin, install the Chef Development Kit (also known as Chef DK), which is an assortment of tools built by the Chef community. You will need this to use the chef command-line tool.

https://docs.aws.amazon.com/opsworks/latest/userguide/best-practices-packaging-cookbooks-locally.html

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223