# Is this a bug in the apache2 cookbook?

**URL:** <https://discourse.chef.io/t/is-this-a-bug-in-the-apache2-cookbook/2427>\
**Category:** Chef Infra (archive)\
**Created:** [January 8, 2012, 10:51am UTC](https://discourse.chef.io/t/is-this-a-bug-in-the-apache2-cookbook/2427 "2012-01-08T10:51:59Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Uckun](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/tim_uckun/32/751_2.png) [@Tim\_Uckun](https://discourse.chef.io/u/Tim_Uckun)\
**Post date:** [January 8, 2012, 10:51am UTC](https://discourse.chef.io/t/is-this-a-bug-in-the-apache2-cookbook/2427/1 "2012-01-08T10:51:59Z")

</div>

I think I know why the passenger-apache2 cookbook is failing. I think  
the problem is with the apache2 cookbook. Here is the module in  
question [https://github.com/opscode/cookbooks/blob/master/apache2/definitions/apache\_module.rb](https://github.com/opscode/cookbooks/blob/master/apache2/definitions/apache_module.rb)

Notice that it does not create the load file if the OS is  
debian/ubuntu. I changed the recipe to add debian and ubuntu and it  
seems to run OK.

Seems like a simple fix but I thought I’d run it by you guys first in  
case I am missing something.

---

<div class="post-metadata">

**Author:** ![werebus](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/werebus/32/24_2.png) [@werebus](https://discourse.chef.io/u/werebus)\
**Post date:** [January 9, 2012, 1:40pm UTC](https://discourse.chef.io/t/is-this-a-bug-in-the-apache2-cookbook/2427/2 "2012-01-09T13:40:15Z")

</div>

Hey Tim,

I believe that bit of code is part of an effort by the author of the  
cookbook to make all of the flavors of Linux have a Debian-like Apache  
configuration setup. Any time I've installed an Apache module on Ubuntu,  
the .load file has always come with it. Have you found this not to be the  
case?

-Matt Moretti

On Sun, Jan 8, 2012 at 5:51 AM, Tim Uckun [timuckun@gmail.com](mailto:timuckun@gmail.com) wrote:

> I think I know why the passenger-apache2 cookbook is failing. I think  
> the problem is with the apache2 cookbook. Here is the module in  
> question  
> [https://github.com/opscode/cookbooks/blob/master/apache2/definitions/apache\_module.rb](https://github.com/opscode/cookbooks/blob/master/apache2/definitions/apache_module.rb)
> 
> Notice that it does not create the load file if the OS is  
> debian/ubuntu. I changed the recipe to add debian and ubuntu and it  
> seems to run OK.
> 
> Seems like a simple fix but I thought I'd run it by you guys first in  
> case I am missing something.

---

<div class="post-metadata">

**Author:** ![Tim\_Uckun](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/tim_uckun/32/751_2.png) [@Tim\_Uckun](https://discourse.chef.io/u/Tim_Uckun)\
**Post date:** [January 9, 2012, 8:42pm UTC](https://discourse.chef.io/t/is-this-a-bug-in-the-apache2-cookbook/2427/3 "2012-01-09T20:42:11Z")

</div>

> I believe that bit of code is part of an effort by the author of the  
> cookbook to make all of the flavors of Linux have a Debian-like Apache  
> configuration setup. Any time I've installed an Apache module on Ubuntu,  
> the .load file has always come with it. Have you found this not to be the  
> case?

If the .load file and the .conf file are both in the mods-enabled  
directory then a2enmod will handle both of them properly. In this  
case the recipe was not creating the .load file if the OS is  
ubuntu/debian so I think that's clearly not right.

---

<div class="post-metadata">

**Author:** ![AJ\_Christensen](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/aj_christensen/32/525_2.png) [@AJ\_Christensen](https://discourse.chef.io/u/AJ_Christensen)\
**Post date:** [January 9, 2012, 9:13pm UTC](https://discourse.chef.io/t/is-this-a-bug-in-the-apache2-cookbook/2427/4 "2012-01-09T21:13:21Z")

</div>

Right, the 'a2enmod' / 'a2dismod' script manages the symlinks. On  
non-ubuntu/debian systems, this has to be managed by robot.

Hope this helps!

Cheers,

AJ

On 10 January 2012 09:42, Tim Uckun [timuckun@gmail.com](mailto:timuckun@gmail.com) wrote:

> > I believe that bit of code is part of an effort by the author of the  
> > cookbook to make all of the flavors of Linux have a Debian-like Apache  
> > configuration setup. Any time I've installed an Apache module on Ubuntu,  
> > the .load file has always come with it. Have you found this not to be the  
> > case?
> 
> If the .load file and the .conf file are both in the mods-enabled  
> directory then a2enmod will handle both of them properly. In this  
> case the recipe was not creating the .load file if the OS is  
> ubuntu/debian so I think that's clearly not right.

---

<div class="post-metadata">

**Author:** ![Tim\_Uckun](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/tim_uckun/32/751_2.png) [@Tim\_Uckun](https://discourse.chef.io/u/Tim_Uckun)\
**Post date:** [January 9, 2012, 9:16pm UTC](https://discourse.chef.io/t/is-this-a-bug-in-the-apache2-cookbook/2427/5 "2012-01-09T21:16:23Z")

</div>

On Tue, Jan 10, 2012 at 10:13 AM, AJ Christensen [aj@junglist.gen.nz](mailto:aj@junglist.gen.nz) wrote:

> Right, the 'a2enmod' / 'a2dismod' script manages the symlinks. On  
> non-ubuntu/debian systems, this has to be managed by robot.

Again the issue is not the management of the files the issue is the  
creation of the files. The apache2 recipe does not create the .load  
file for ubuntu/debian based systems (at least not for the passenger  
module).

Maybe the fault is with the passenger\_apache2 recipe I don't know but  
in order to install passenger on ubuntu I had to add ubuntu to the  
list like this...

if platform?("redhat", "centos", "scientific", "fedora", "arch",  
"suse" , "debian", "ubuntu")  
file "#{node['apache']['dir']}/mods-available/#{params[:name]}.load" do  
content "LoadModule #{params[:name]}\_module #{params[:module\_path]}\n"  
mode 0644  
end  
end

---

<div class="post-metadata">

**Author:** ![AJ\_Christensen](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/aj_christensen/32/525_2.png) [@AJ\_Christensen](https://discourse.chef.io/u/AJ_Christensen)\
**Post date:** [January 9, 2012, 9:23pm UTC](https://discourse.chef.io/t/is-this-a-bug-in-the-apache2-cookbook/2427/6 "2012-01-09T21:23:01Z")

</div>

On 10 January 2012 10:16, Tim Uckun [timuckun@gmail.com](mailto:timuckun@gmail.com) wrote:

> On Tue, Jan 10, 2012 at 10:13 AM, AJ Christensen [aj@junglist.gen.nz](mailto:aj@junglist.gen.nz) wrote:
> 
> > Right, the 'a2enmod' / 'a2dismod' script manages the symlinks. On  
> > non-ubuntu/debian systems, this has to be managed by robot.
> 
> Again the issue is not the management of the files the issue is the  
> creation of the files. The apache2 recipe does not create the .load  
> file for ubuntu/debian based systems (at least not for the passenger  
> module).
> 
> Maybe the fault is with the passenger\_apache2 recipe I don't know but  
> in order to install passenger on ubuntu I had to add ubuntu to the  
> list like this...

Yes, the fault is with the passenger\_apache2 recipe.

Brutalizing the apache2 module definition (used by all of the  
apache2::mod\_\* recipes) will mean that your system is generating .load  
files where it is not necessary to do so -- the .load files are  
provided by the system with the libapache2-foo-bar packages.

I'd suggest rendering the passenger .load module configuration file to  
the "mods-available" directory for Apache2 then using the standard  
a2enmod/a2dismod / apache2\_mod definition code, without modification.

Cheers,

AJ

> if platform?("redhat", "centos", "scientific", "fedora", "arch",  
> "suse" , "debian", "ubuntu")  
> file "#{node['apache']['dir']}/mods-available/#{params[:name]}.load" do  
> content "LoadModule #{params[:name]}\_module #{params[:module\_path]}\n"  
> mode 0644  
> end  
> end

---

<div class="post-metadata">

**Author:** ![Tim\_Uckun](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/tim_uckun/32/751_2.png) [@Tim\_Uckun](https://discourse.chef.io/u/Tim_Uckun)\
**Post date:** [January 9, 2012, 9:36pm UTC](https://discourse.chef.io/t/is-this-a-bug-in-the-apache2-cookbook/2427/7 "2012-01-09T21:36:06Z")

</div>

> Yes, the fault is with the passenger\_apache2 recipe.
> 
> Brutalizing the apache2 module definition (used by all of the  
> apache2::mod\_\* recipes) will mean that your system is generating .load  
> files where it is not necessary to do so -- the .load files are  
> provided by the system with the libapache2-foo-bar packages.
> 
> I'd suggest rendering the passenger .load module configuration file to  
> the "mods-available" directory for Apache2 then using the standard  
> a2enmod/a2dismod / apache2\_mod definition code, without modification.

Thanks AJ. I guess I will see where the passenger\_apache2 recipe is  
failing and see if I can fix that instead.

---

<div class="post-metadata">

**Author:** ![Tim\_Uckun](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/tim_uckun/32/751_2.png) [@Tim\_Uckun](https://discourse.chef.io/u/Tim_Uckun)\
**Post date:** [January 10, 2012, 2:49am UTC](https://discourse.chef.io/t/is-this-a-bug-in-the-apache2-cookbook/2427/8 "2012-01-10T02:49:19Z")

</div>

On Tue, Jan 10, 2012 at 10:36 AM, Tim Uckun [timuckun@gmail.com](mailto:timuckun@gmail.com) wrote:

> > Yes, the fault is with the passenger\_apache2 recipe.

I have just been looking at this and I really think this is a problem  
with the apache2 recipe and not the passenger recipe. Here is the  
flow.

The passenger recipe creates the module and does the following.

include\_recipe "passenger\_apache2"

template "#{node[:apache][:dir]}/mods-available/passenger.conf" do  
cookbook "passenger\_apache2"  
source "passenger.conf.erb"  
owner "root"  
group "root"  
mode "644"  
end

apache\_module "passenger" do  
module\_path node[:passenger][:module\_path]  
end

As you can see from above it is asking the apache\_module provider  
(defined in the apache2 recipe) to create a module for it. The  
apache\_module recipe looks like this.

if params[:conf]  
apache\_conf params[:name]  
end

if platform?("redhat", "centos", "scientific", "fedora", "arch", "suse" )  
file "#{node['apache']['dir']}/mods-available/#{params[:name]}.load" do  
content "LoadModule #{params[:name]}\_module #{params[:module\_path]}\n"  
mode 0644  
end  
end

So it refuses to create the .load file unless the platform matches the  
ones listed.

I can see no rational reason for this. How is apache supposed to load  
the module without a LoadModule directive?

It seems to me that the passenger recipe is doing the right thing. In  
fact from the looks of it it could just pass the config params to  
apache\_module too instead of creating it's own .conf file.

So at this stage I have the following options.

1. Change the apache recipe and add ubuntu and debian to the list.
2. Change the passenger recipe to create the load file
3. create the load file outside of either one of these recipes.

---

<div class="post-metadata">

**Author:** ![werebus](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/werebus/32/24_2.png) [@werebus](https://discourse.chef.io/u/werebus)\
**Post date:** [January 10, 2012, 3:42am UTC](https://discourse.chef.io/t/is-this-a-bug-in-the-apache2-cookbook/2427/9 "2012-01-10T03:42:43Z")

</div>

The Apache cookbook doesn't need to create .load files for nearly all  
modules because the Debian-based distros package one with the module.

Typically, you would install -- for example -- mod\_perl with a "package"  
resource. This ends up being more-or-less equivalent to running "apt-get  
install libapache2-mod-perl2" on the host. For every Apache module I've  
ever installed (on Ubuntu), that results in the creation of .load file and,  
sometimes, a .conf file in /etc/apache2/mods-available/

Now, because the .conf file contains configuration, you'll probably want to  
manage its contents with Chef, but we can rely on the .load file being  
there on any Debian-based distro (hence why it's only explicitly created on  
the non-Debian-based ones).

Passenger is a little different, as it is built from source by a rubygem.  
In my opinion, there is a bug with the current version of the  
passenger\_apache2 cookbook. It tries to rely on the .load file creating  
ability of the apache\_module definition which (as you've found) won't work  
on Ubuntu or Debian. This looks to be a recent  
change[https://github.com/cookbooks/passenger\_apache2/commit/679784f96898c9221d670630ebf32c6cf8a0a292](https://github.com/cookbooks/passenger_apache2/commit/679784f96898c9221d670630ebf32c6cf8a0a292)in  
the cookbook.

Of course, the apache2 cookbook could just always create the .load file  
regardless of distribution. However, for all cases except passenger it  
would be redundant and might introduce other issues.

In any case, if you believe you've found a bug in an Opscode cookbook, you  
should report it [http://tickets.opscode.com/browse/COOK](http://tickets.opscode.com/browse/COOK).

Good luck

-Matt Moretti

On Mon, Jan 9, 2012 at 9:49 PM, Tim Uckun [timuckun@gmail.com](mailto:timuckun@gmail.com) wrote:

> On Tue, Jan 10, 2012 at 10:36 AM, Tim Uckun [timuckun@gmail.com](mailto:timuckun@gmail.com) wrote:
> 
> > > Yes, the fault is with the passenger\_apache2 recipe.
> 
> I have just been looking at this and I really think this is a problem  
> with the apache2 recipe and not the passenger recipe. Here is the  
> flow.
> 
> The passenger recipe creates the module and does the following.
> 
> include\_recipe "passenger\_apache2"
> 
> template "#{node[:apache][:dir]}/mods-available/passenger.conf" do  
> cookbook "passenger\_apache2"  
> source "passenger.conf.erb"  
> owner "root"  
> group "root"  
> mode "644"  
> end
> 
> apache\_module "passenger" do  
> module\_path node[:passenger][:module\_path]  
> end
> 
> As you can see from above it is asking the apache\_module provider  
> (defined in the apache2 recipe) to create a module for it. The  
> apache\_module recipe looks like this.
> 
> if params[:conf]  
> apache\_conf params[:name]  
> end
> 
> if platform?("redhat", "centos", "scientific", "fedora", "arch", "suse" )  
> file "#{node['apache']['dir']}/mods-available/#{params[:name]}.load" do  
> content "LoadModule #{params[:name]}\_module #{params[:module\_path]}\n"  
> mode 0644  
> end  
> end
> 
> So it refuses to create the .load file unless the platform matches the  
> ones listed.
> 
> I can see no rational reason for this. How is apache supposed to load  
> the module without a LoadModule directive?
> 
> It seems to me that the passenger recipe is doing the right thing. In  
> fact from the looks of it it could just pass the config params to  
> apache\_module too instead of creating it's own .conf file.
> 
> So at this stage I have the following options.
> 
> 1. Change the apache recipe and add ubuntu and debian to the list.
> 2. Change the passenger recipe to create the load file
> 3. create the load file outside of either one of these recipes.

---

<div class="post-metadata">

**Author:** ![Tim\_Uckun](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/tim_uckun/32/751_2.png) [@Tim\_Uckun](https://discourse.chef.io/u/Tim_Uckun)\
**Post date:** [January 10, 2012, 8:46am UTC](https://discourse.chef.io/t/is-this-a-bug-in-the-apache2-cookbook/2427/10 "2012-01-10T08:46:59Z")

</div>

> Of course, the apache2 cookbook could just always create the .load file  
> regardless of distribution. However, for all cases except passenger it  
> would be redundant and might introduce other issues.
> 
> In any case, if you believe you've found a bug in an Opscode cookbook, you  
> should report it.

I have filed a bug [http://tickets.opscode.com/browse/COOK-967](http://tickets.opscode.com/browse/COOK-967)

I have filed the bug against the passenger cookbook but I still think  
the behaviour of the apache2 recipe should be changed. In my opinion  
the apache\_module call is an imperative and the end result should be a  
.load file. Of course the call should be idempotent so it would not  
trigger a reload if is already correct.

One other thing I noticed is that the following sequence of calls will  
cause unexpected behavior.

apache\_module "passenger" do  
module\_path "/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.7/ext/apache2/mod\_passenger.so"  
end

...later on....

apache\_module "passenger" do  
enable true (or false)  
end

Causes the run to crash. It crashes because the second call overwrote  
the .load file to read "LoadModule passenger\_module  
mod\_pasenger.so\n". Unless you specify the load path every time the  
call is made it gets reset to the default. In this case the default  
.so file does not exist and apache exits with an error.

IMHO this behaviour is unexpected and the implementation should be  
done differently. One possible approach might be to use an action so  
you could have action :create action :enable action :disable.

Anyway the bug has been filed. I have gotten around the problem by  
rewriting the passenger\_apache2 recipe to read like this.

template "#{node[:apache][:dir]}/mods-available/passenger.conf" do  
cookbook "passenger\_apache2"  
source "passenger.conf.erb"  
owner "root"  
group "root"  
mode "644"  
end

file "#{node[:apache][:dir]}/mods-available/passenger.load" do  
cookbook "passenger\_apache2"  
content "LoadModule passenger\_module #{node[:passenger][:module\_path]}\n"  
owner "root"  
group "root"  
mode 0644  
end

apache\_module "passenger" do  
module\_path node[:passenger][:module\_path]  
enable true  
end

All three stanzas are needed in order to enable the module.
