Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opsworks Chef 12 recipes

Tags:

Has anyone attempted to convert Opsworks Chef v11 recipes to Chef v12?

Im running multiple stacks on Chef 11 and decided to start converting some of them to Chef 12. Since AWS dropped their opsworks app layers, such as rails layer recipes, we (opsworks users) are now responsible for creating deploy user, git checkout repos into deploy_to, etc.

Its all good with flexibility and no more namespace conflicts, but we are missing all that good stuff opsworks was giving us for free.

Wonder if someone converted recipes for Chef 12 and open-sourced? Otherwise, is community interested in these recipes at all? Im pretty sure Im not alone here.

Thank you in advance!

like image 318
vlgs Avatar asked Mar 30 '16 21:03

vlgs


People also ask

Which AWS service can you use to create Chef recipes?

AWS Systems Manager is an ideal platform to manage the distribution and execution of Chef recipes across your instances. It augments Chef's native functionality, with powerful features such as scheduled execution, rate control, compliance reports, and enhanced logging capabilities.

What is cookbook in AWS?

A production-level AWS OpsWorks Stacks stack typically requires some customization, which often means implementing a custom Chef cookbook. A cookbook is a package file that contains configuration information, including instructions called recipes.

What is AWS Chef?

Chef is an automation patform that helps you automate operational tasks at scale. You can use Chef to manage both Amazon Elastic Compute Cloud (Amazon EC2) instances and on-premises servers running Linux or Windows.


2 Answers

The opsworks_ruby cookbook on the Supermarket is basically everything you need. It even puts the apps into the same directories (i.e. /srv/www/app_name/), sets up your database.yml, etc, etc.

The main difference between this recipe and other non-OpsWorks recipes is that this will pull everything out of the OpsWorks configuration for you. You don't have to customize the recipes, just make sure your app and layers are named correctly - it'll build everything from there - including your RDS configuration for the database.yml!

The main difference is that the layers in OpsWorks won't be "Ruby aware" so you won't have fields for Rails-ish or Ruby-ish things and instead will need to manage those elsewhere. The way ENV vars is loaded is a little different too.

Also be sure to read up on AWS' implementation of Chef 12 for OpsWorks. They technically have two chef cookbooks running, their internal one and yours. Theirs include managing the agent is up-to-date, loading up users (for ssh), wiring up monitoring, etc. You'll have to manage the rest.

We've either replaced stuff from their huge cookbook with individual cookbooks from the Supermarket or just rewrote it. For instance, the old Chef 11 opsworks_initial_setup had a couple things around tweaking network and linux settings - we recreated that.

It also does use deploy users as applicable, for instance:

$ ps -eo user,command USER COMMAND // snip root nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf aws opsworks-agent: master 10820 aws opsworks-agent: keep_alive of master 10820 aws opsworks-agent: statistics of master 10820 aws opsworks-agent: process_command of master 10820 deploy unicorn_rails master --env production --daemonize -c /srv/www/app/shared/config/unicorn.conf deploy unicorn_rails worker[0] --env production --daemonize -c /srv/www/app/shared/config/unicorn.conf deploy unicorn_rails worker[1] --env production --daemonize -c /srv/www/app/shared/config/unicorn.conf deploy unicorn_rails worker[2] --env production --daemonize -c /srv/www/app/shared/config/unicorn.conf deploy unicorn_rails worker[3] --env production --daemonize -c /srv/www/app/shared/config/unicorn.conf nginx nginx: worker process nginx nginx: worker process

Just a small example of the process output but root boots things as needed and each process utilizes their own users to limit rights and access.

like image 162
databyte Avatar answered Nov 15 '22 04:11

databyte


I think the most common way is to use the "application" cookbook from the supermarket: https://supermarket.chef.io/cookbooks/application/versions/4.1.6 (which is also based on Poise). Attention: use version ~4, they removed almost all of the good features in v5.

It will create the directory structure, supports different deploy-strategies and offers some events to hook. Be aware: In my opinion, the Opsworks documentation is semi-good when it comes to the "deploy with opsworks and chef12" topic: The information from the gui (like repo-url etc), is not on the node object but in a databag from the application. For debugging it can be very helpful to have a look into the /var/chef/runs/<run-id>/ directory to see what is available from where. Small snippet that shows the idea:

app = search("aws_opsworks_app").first
application "#{app['shortname']}" do
  owner 'root'
  group 'root'
  repository app['app_source']['url']
  revision   'master'
  path "/srv/#{app['shortname']}"
end

This will create the releases/current directory structure on /srv and checkout the code. Note: you could think that ssh-key you specify in the GUI is somehow automatically put in the proper place. Its not, you'll have to take care of that on your own. Check the chef11 opsworks cookbook: https://github.com/aws/opsworks-cookbooks/blob/release-chef-11.10/scm_helper/libraries/git.rb

like image 22
leberknecht Avatar answered Nov 15 '22 06:11

leberknecht