aws / opsworks-cookbooks

Chef Cookbooks for the AWS OpsWorks Service
Other
1.05k stars 1.23k forks source link

Apache VHost Config Deployment Failure #305

Open jc1arke opened 9 years ago

jc1arke commented 9 years ago

Hey there

Since last night, I have been issues on OpsWorks where when I try to deploy a new server or deploy one of our apps, we constantly get the error message below:

Chef::Mixin::Template::TemplateError
------------------------------------
undefined method `each' for nil:NilClass

Digging around, I found that is due to L41 in mod_php5_apache2/templates/default/web_app.conf.erb

The gist is, it needs to change to cater for when @environment is not set or empty, not just work on the assumption it is there and has values. It's nil, so the each will fail.

This was mentioned on a previous issue (https://github.com/aws/opsworks-cookbooks/issues/228), but I don't think this has been resolved as yet. See https://github.com/aws/opsworks-cookbooks/blob/release-chef-11.10/mod_php5_apache2/templates/default/web_app.conf.erb, it's still there and unpatched.

kirkhansen commented 9 years ago

I am also facing this error when following through the simple php tutorial.

saidababuchanda commented 9 years ago

Hi All,

This is an issue if you are using Berksfile in OpsWorks and the Berksfile has dependencies on apache2 cookbook pulled from super market.

ex:: if your Berksfile has a dependency like below::

!/usr/bin/env ruby

-- encoding : utf-8 --

source "https://api.berkshelf.com"

eset/metadata

cookbook 'mongodb' cookbook 'mod_security'

Here, if you look at mod_security dependencies here:: https://supermarket.chef.io/cookbooks/mod_security#dependencies

It depends on

apache2 >= 0.0.0 build-essential >= 0.0.0

You see apache2 there, and OpsWorks also has cookbook with the same name, so the problem is you are overriding the OpsWorks cookbook with apache2 cookbook from supermarket and its causing the issue.

Solution::

 1.  avoid dependencies which installs conflicting cookbooks with OpsWorks.
jc1arke commented 9 years ago

@saidababuchanda thanks for the feedback on this. I agree, one should have a look at the dependencies of 3rd party cookbooks/recipes, but even so one should follow a strict rule in development that a object is not always as you expect it to be. With the AWS OpsWorks recipe, with no 3rd party recipes, it still has the issue where it fails on <% @environment.each do |key, value| %> because @environment is actually nil, thus it fails with each method not found for NilClass. I tested this on a Chef Solo instance, separate from the OpsWorks stacks.

saidababuchanda commented 9 years ago

@jc1arke can you please give the entire sack trace of the issue?sorrry if I have misread your issue.

jc1arke commented 9 years ago

@saidababuchanda will post it once I am back on office on Monday, but will see if I can't replicate it over the weekend

saidababuchanda commented 9 years ago

@jc1arke sure , have a good one..