Debug Chef12 recipe with AWS OpsWorks CLI

  02 Nov 2016

Let’s say we have haproxy recipe that we want to debug

We must run recipe with OpsWorks via web interface ( Deploy > Run Command > Execute Recipes - haproxy ) first.

Then we can login into instance and try running opsworks-agent-cli list The last command we run should be execute_recipes:

    $ opsworks-agent-cli list
    2016-10-31T11:36:12        configure
    2016-10-31T11:54:36        execute_recipes

And add require 'pry' in the recipe that we are going to debug Opsworks Cookbook stored in /var/chef/cookbooks

So, presumingly we edit haproxy recipe at /var/chef/cookbooks/recipes/haproxy.rb

# # Cookbook Name:: mycookbook # Recipe:: haproxy

require ‘pry’ binding.pry

pool_members = search(“node”, “role:rails-app”)   []

After we added, we can repeat our last execute_recipes run with opsworks-agent-cli run

Frame number: 0/24

From: /var/chef/runs/7e58ef5c-2c91-4963-adc4-0b94335cc16a/local-mode-cache/cache/cookbooks/recipes/haproxy.rb @ line 42 Chef::Mixin::FromFile#from_file:

1: require
2: binding.pry
3:  => 4: pool_members = search("node", "role:rails-app}") || []

[1] pry(#)>

In the PRY prompt during of a Chef run, you are now able to inspect the variables that are available during the chef run. This makes troubleshooting recipe somewhat easier.

comments powered by Disqus