Ask Your Question
1

'file' resource for custom apache::mod - puppetlabs-apache

asked 2015-04-22 17:59:19 -0500

BKC gravatar image

updated 2015-04-23 10:29:34 -0500

Quesiton:

Can someone provide an example of how a custom apache module, sourced using the file resource can be applied correctly using the puppetlabs-apache forge module?

Overview:

I am having a (sub)class ordering issue with the puppetlabs-apache forge module that I haven't been able to tackle. I have a custom apache module that I need to supply to apache via a 'file' resource. The base apache mod has to install first, the the file resource needs to be applied into /etc/httpd/modules, then the apache::mod (proxywstunnel) has to be applied. I can't figure out how to declare this ordrer without creating a dependency cycle or apache tries to start but the modproxy_wstunnel.so file isn't available so it fails.

If the apache::mod had a 'source' parameter, I wouldn't need to use the 'file' resources.

=================

class td_npt_mod::apache::install {


class { 'apache':  }

file {'/etc/httpd/modules/mod_proxy_wstunnel.so' :

   ensure => file,

  source => ["puppet:///modules/td_npt_mod/mod_proxy_wstunnel.so"],

}

apache::mod { 'proxy_wstunnel': 

 require => File['/etc/httpd/modules/mod_proxy_wstunnel.so'],  

} 

include apache::dev

include apache::mod::proxy

apache::custom_config { 'tomcat':

  source => ["puppet:///modules/td_npt_mod/tomcat.conf"],

}

}
edit retag flag offensive close merge delete

Comments

Have you tried adding dependency chains to make sure the resources are applied in the desired order? At what point did you have code that generated a dependency cycle? Please post that version as well.

GregLarkin gravatar imageGregLarkin ( 2015-04-22 22:22:33 -0500 )edit

The code above does not cause a dependency cycle, it just causes an apache syntax error because the service tries to start before 'mod_proxy_wstunnel.so is in place. I have tried chaining arrows and run stages, both of which do cause a dependency cycles with apache.

BKC gravatar imageBKC ( 2015-04-23 10:19:40 -0500 )edit

Have you tried adding "before => Class['apache::service']," to your apache::mod resource?

GregLarkin gravatar imageGregLarkin ( 2015-04-23 11:01:54 -0500 )edit

The apache module must live in /etc/httpd/modules, so apache must be installed before apache::mod runs so that this path exists. apache won't install if I try to manage (via a file resource) /etc/httpd/modules before calling the apache class.

BKC gravatar imageBKC ( 2015-04-23 17:20:52 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2015-04-23 23:24:18 -0500

GregLarkin gravatar image

updated 2015-04-24 12:10:05 -0500

I wonder if something like this would work (untested, YMMV):

UPDATED

class td_npt_mod::apache::install {
  include apache
  include apache::package # UPDATED to allow dependency below and hides platform specifics
  include apache::dev
  include apache::mod::proxy

  file { '/etc/httpd/modules/mod_proxy_wstunnel.so':
    ensure  => file,
    source  => 'puppet:///modules/td_npt_mod/mod_proxy_wstunnel.so',
    require => Class['apache::package'], # Now able to depend on the class instead of a directly on the package resource
  }

  apache::mod { 'proxy_wstunnel': 
    require => File['/etc/httpd/modules/mod_proxy_wstunnel.so'],
    notify  => Class['apache::service'], # UPDATED to notify the service when the module has been installed
  }

  apache::custom_config { 'tomcat':
    source => 'puppet:///modules/td_npt_mod/tomcat.conf',
  }
}

What that should do is get the Apache package installed before any of the mod_proxy_wstunnel.so installation/configuration is performed. Once the .so file is in place, then the Apache service will be configured and started.

I'm not sure what's going on with the apache::custom_config defined type, so you may need to put some dependency attributes in it to get it applied in the correct order, but I hope this is a good starting point.

edit flag offensive delete link more

Comments

FWIW, requiring the apache::service still doesn't work after including apache::service Error: Duplicate declaration: Package[httpd] is already declared in file /tmp/vagrant-puppet/modules-560261cb716e1e97cb2dc6fc24fa9a39/apache/manifests/package.pp:58; cannot redeclare at /tmp/vagrant-puppet/modu

BKC gravatar imageBKC ( 2015-04-24 16:09:51 -0500 )edit

Fair enough, I guess the only option is to depend directly on Package['httpd'].

GregLarkin gravatar imageGregLarkin ( 2015-04-24 16:28:32 -0500 )edit

Great solution! This helped me to resolve the ordering issue in our custom module written based on apache code base.

Sastha gravatar imageSastha ( 2015-09-24 15:59:10 -0500 )edit
0

answered 2015-04-24 11:16:58 -0500

BKC gravatar image

Greg - Thank you very much for helping with this.

The "require => Class['apache::package']," statement gave me the following error:

Error: Could not find dependency Class[Apache::Package] for File[/etc/httpd/modules/mod_proxy_wstunnel.so]  at /tmp/vagrant-puppet/modules-560261cb

But this lead me to trying the 'require => Package['httpd']' statement in the file resource instead which seems to work. Such a small fix to get this working! I wish this was better documented in the puppetlabs-forge module or the solution was baked into the module itself.

class td_npt_mod::apache::install {
include apache::dev
include apache::mod::proxy

class { 'apache':
  default_mods => true,
  default_vhost => false,
}

file {'/etc/httpd/modules/mod_proxy_wstunnel.so' :
  ensure => file,
  source => ["puppet:///modules/td_npt_mod/mod_proxy_wstunnel.so"],
  require => Package['httpd'],
}

apache::mod { 'proxy_wstunnel': 
  require => File['/etc/httpd/modules/mod_proxy_wstunnel.so'],
  before  => Class['apache::service'],
} 

apache::custom_config { 'tomcat':
  source => ["puppet:///modules/td_npt_mod/tomcat.conf"],
}

}
edit flag offensive delete link more

Comments

Great, glad you found a solution. I have updated my original answer below to correct the unknown resource issue that you detected, but can certainly continue to depend on Package['httpd'], as long as you don't try the code on a different OS w/ a different package name. That's why we recommend...

GregLarkin gravatar imageGregLarkin ( 2015-04-24 12:06:21 -0500 )edit

...depending on classes, so the class hides the platform dependencies. I also likely needed to have a "notify" parameter rather than a simple "before". I agree that the non-standard Apache module handling is a difficult to figure out, and the docs don't give a lot of guidance.

GregLarkin gravatar imageGregLarkin ( 2015-04-24 12:07:55 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-04-22 17:59:19 -0500

Seen: 948 times

Last updated: Apr 24 '15