thias / puppet-nagios

Puppet Nagios module
Other
23 stars 71 forks source link

httpd-nagios.conf.erb undefined method `each' for nil:NilClass #19

Open pythianali opened 10 years ago

pythianali commented 10 years ago

Hi,

I am using v0.4.7 of the module and have also installed your apache_httpd (v0.4.2) and php (v0.3.12) modules as well. The following error shows up on my puppet run:

Filepath: /etc/puppet/environments/production/modules/nagios/templates/apache_httpd/httpd-nagios.conf.erb Line: 7 Detail: undefined method `each' for nil:NilClass at /etc/puppet/environments/production/modules/nagios/manifests/server.pp:20 on node

Whats noticeable is that I do not have a value for apache_httpd_conf_content in my class, which was copied from an older running installation.

Any ideas?

pythianali commented 10 years ago

I was able to pass this error by adding the following directive in the nagios::server class

apache_allowed_from => '127.0.0.1'

bartlomiej2 commented 10 years ago

Confirming, I have same issue too.

thias commented 10 years ago

This might be fixed in the master branch of the nagios module, could you maybe try it out and report back?

bartlomiej2 commented 10 years ago

I've install nagios module from git and now it fails with this error:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to parse template nagios/apache_httpd/httpd-nagios.conf.erb:
  Filepath: /etc/puppet/modules/nagios/templates/apache_httpd/httpd-nagios.conf.erb
  Line: 4
  Detail: undefined method `empty?' for nil:NilClass
 at /etc/puppet/manifests/classes/nagios_server.pp:5 on node samas
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

I have two questions.

How to define "allowed_from" apache directive in puppet? I tried this two ways: apache_allowed_from => [ "192.168.0.0/24" ], apache_allowed_from => "192.168.0.0/24", but without any success.

Does nagios module require ruby version > 2? Because I've 1.8.7

ruby --version
ruby 1.8.7 (2011-06-30 patchlevel 352) [i386-linux]
NMerch commented 10 years ago

I'm running 1.8.7 on CentOS 6.5 without issue.

$ruby --version ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux] $puppet --version 3.5.1

bartlomiej2 commented 10 years ago

NMerc, can you show how you define "allowed_from" in puppet config for nagios server? Do you use "apache_allowed_from"?

NMerch commented 10 years ago

I'm not using it, sorry.

bartlomiej2 commented 10 years ago

Anyway if I delete "apache_allowed_from" from puppet config it fails with error I've listed above.

thias commented 10 years ago

It should work with apache_allowed_from => [ '192.168.0.0/24' ], as it expects an array. Could you please double check with the git master code?

andybrucenet commented 9 years ago

Use the Source, Luke.

Solved. Problem is early compilation of template('filename') as in Thias' example:

class { 'nagios::server':
  apache_httpd_ssl             => false,
  apache_httpd_conf_content    => template('my/httpd-nagios.conf.erb'),

That loses; the template causes compile before class variables are available!

I patched Thias' nagios/manifests/server.pp file to permit new variable:

$apache_httpd_conf_content_name    = undef,

Then further down, modified block as follows:

# Set a default content template if no content/source is specified
  # ABr, 20141029: use new variable apache_httpd_conf_content_name
  if $apache_httpd_conf_source == '' {
    if $apache_httpd_conf_content_name != '' {
      # ABr, 20141029: permit late compilation of ERB
      $apache_httpd_conf_content_final = template($apache_httpd_conf_content_name)
    } elsif $apache_httpd_conf_content == '' {
      $apache_httpd_conf_content_final = template("${module_name}/apache_httpd/httpd-nagios.conf.erb")
    } else {
      $apache_httpd_conf_content_final = $apache_httpd_conf_content
    }
  }

That wins! All variables are now available.

Let me know if any interest, I'll post the modified files and send them to Thias.