Divide init.pp into components

598 views
Skip to first unread message

David Jarosch

unread,
Jan 16, 2014, 6:16:02 AM1/16/14
to puppet...@googlegroups.com
Hey guys,

I'm having some problems dividing my init.pp into components like package.pp, config.pp and service.pp. Unfortunately I'm getting several error's after running puppet-lint like:

ERROR: nrpe::package not in autoload module layout on line 1
ERROR: nrpe::service not in autoload module layout on line 1
ERROR: Syntax error (try running `puppet parser validate <file>`) on line 3
ERROR: nrpe::config not in autoload module layout on line 1

etc.

Puppet parser show's following error:

puppet parser validate /etc/puppet/git/modules/nrpe/manifests/init.pp
Error: Could not parse for environment production: Could not match  '::nrpe::package': at /etc/puppet/git/modules/nrpe/manifests/init.pp:2

On client machine:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find class nrpe

Here my code, maybe someone of you can give me a hint where to look at:

init.pp

### INSTALLS NRPE INCLUDING DEFINING SERVER AND SETTING UP PLUGINS ###
class nrpe {
  class { '::nrpe::package': } ->
  class { '::nrpe::config': }  ->
  class { '::nrpe::service': } ->
  Class['nrpe']
}

package.pp

class nrpe::package {
  package { 'nagios-nrpe-server':
    ensure      => 'latest',
    require     => Class['apt::update'],
  }

  ### INSTALL NRPE PLUGINS WITHOUT ADDITIONAL RECOMMENDED PACKAGES
  exec { 'nagios-nrpe-plugin':
    unless      => '/usr/bin/dpkg -l |grep nagios-nrpe-plugin',
    require     => Class['nrpe::package'],
    command     => '/usr/bin/apt-get install nagios-nrpe-plugin -y --no-install-recommends';
  }

  ### INSTALL ICINGA PLUGINS WITHOUT ADDITIONAL RECOMMENDED PACKAGES
  exec { 'nagios-plugins':
    unless      => '/usr/bin/dpkg -l |grep nagios-plugins',
    require     => Class['nrpe::package'],
    command     => '/usr/bin/apt-get install nagios-plugins -y --no-install-recommends';
  }
}

config.pp

class nrpe::config {
  file {
    '/etc/nagios/nrpe.cfg':
      source    => 'puppet:///modules/nrpe/nrpe.cfg',
      require   => Class['nrpe::package'],
      notify    => Class['nrpe::service'],
      mode      => '0644',
      owner     => 'nagios',
      group     => 'nagios';

    '/etc/init.d/nrpe':
      source    => 'puppet:///modules/nrpe/nrpe_init.d',
      require   => Class['nrpe::package'],
      notify    => Class['nrpe::service'],
      mode      => '0755',
      owner     => 'root',
      group     => 'root';

    '/etc/nagios/nrpe.d/nrpe_all.cfg':
      source    => 'puppet:///modules/nrpe/nrpe_all',
      require   => Class['nrpe::package'],
      notify    => Class['nrpe::service'],
      mode      => '0644',
      owner     => 'nagios',
      group     => 'nagios';

    '/usr/lib/nagios/plugins/check_linux_raid':
      source    => 'puppet:///modules/nrpe/plugins/check_linux_raid',
      require   => Class['nrpe::package'],
      notify    => Class['nrpe::service'],
      mode      => '0755',
      owner     => 'nagios',
      group     => 'nagios';

    '/usr/lib/nagios/plugins/check_md_raid':
      source    => 'puppet:///modules/nrpe/plugins/check_md_raid',
      require   => Class['nrpe::package'],
      notify    => Class['nrpe::service'],
      mode      => '0755',
      owner     => 'nagios',
      group     => 'nagios';
  }
}

service.pp

class nrpe::service {
  service { 'nrpe':
    ensure      => running,
    enable      => true,
    require     => Class['nrpe::config'],
  }
}

Folderstructure on Puppetmaster:

/etc/puppet/git/modules/nrpe/manifests# tree -d /etc/puppet/git/modules/
/etc/puppet/git/modules/
├── nrpe
│   ├── files
│   │   ├── nrpe_all
│   │   ├── nrpe_cache.cfg
│   │   ├── nrpe.cfg
│   │   ├── nrpe_init.d
│   │   ├── nrpe_var
│   │   ├── plugins
│   │   │   ├── check_linux_raid
│   │   │   ├── check_md_raid
│   │   │   ├── check_memcached.pl
│   │   │   └── check_mongodb.py
│   ├── manifests
│   │   ├── config.pp
│   │   ├── init.pp
│   │   ├── package.pp
│   │   ├── service.pp
│   ├── Modulefile
│   ├── README
│   ├── spec
│   │   └── spec_helper.rb
│   └── tests
│       └── init.pp


Cheers,
David

Gavin Williams

unread,
Jan 16, 2014, 7:20:15 AM1/16/14
to puppet...@googlegroups.com
David

Module layout looks ok from the above...

It's probably worth checking what your puppet master modulepath is set to in puppet.conf, as notice you're using /etc/puppet/git/modules, rather than the normal /etc/puppet/modules.

HTH
Gavin

David Jarosch

unread,
Jan 16, 2014, 7:25:13 AM1/16/14
to puppet...@googlegroups.com
Hey Gavin,

thanks for your reply. The modulepath on puppetmaster should be fine:

/etc/puppet/puppet.conf

[main]
logdir=/var/log/puppet
vardir=/var/lib/puppet
ssldir=/var/lib/puppet/ssl
rundir=/var/run/puppet
factpath=$vardir/lib/facter
templatedir=$confdir/templates
manifestdir = /etc/puppet/git/manifests
modulepath = /etc/puppet/git/modules

Cheers,
David

David Jarosch

unread,
Jan 16, 2014, 7:25:45 AM1/16/14
to puppet...@googlegroups.com
Hey Gavin,

thanks for your reply. The modulepath on puppetmaster should be fine:

/etc/puppet/puppet.conf

[main]
logdir=/var/log/puppet
vardir=/var/lib/puppet
ssldir=/var/lib/puppet/ssl
rundir=/var/run/puppet
factpath=$vardir/lib/facter
templatedir=$confdir/templates
manifestdir = /etc/puppet/git/manifests
modulepath = /etc/puppet/git/modules

Cheers,
David

Am Donnerstag, 16. Januar 2014 13:20:15 UTC+1 schrieb Gavin Williams:

Gavin Williams

unread,
Jan 16, 2014, 7:32:18 AM1/16/14
to puppet...@googlegroups.com
Ah, just spotted what might be another issue in your init.pp file:
---
### INSTALLS NRPE INCLUDING DEFINING SERVER AND SETTING UP PLUGINS ###
class nrpe {
  class { '::nrpe::package': } ->
  class { '::nrpe::config': }  ->
  class { '::nrpe::service': } ->
  Class['nrpe']
}
---
Try dropping "Class['nrpe']", as dont think it's needed, and could quite possibly end-up causing a cyclical dependency... Albeit that's not the error your client is seeing :s

Cheers
Gavin

David Jarosch

unread,
Jan 16, 2014, 7:54:32 AM1/16/14
to puppet...@googlegroups.com
Unfortunately this didn't solve the problem. Maybe it help's to see how I'm including the modules. I have an origin.pp file /etc/puppet/git/manifests/origin.pp which include modules, that are used by all of my servers:

### BASE DEFINITION WHICH ALL OTHER NODES INHERITS FROM ###
node 'origin' {
  include aliases
  include apt
  include apt::update
  include base
  include cron
  include exim
  include fail2ban
  include logrotate
  include monit
  include monit::logstash
  include motd
  include nrpe
  class { 'ntp':
    server  => 'de.pool.ntp.org',
  }
  include ssh
  include sudo
  include puppet
  include puppet::client
  include user
  include vim
}

Then I define node's which inherits from origin:

##### APP SERVER #####
node  'app1...',
      'app2...'
       'app3...'
       'app4...'
       'app5...' inherits 'origin' {
  include apt::deb6
  include base::extended
  include cron::app
  include daemontools::app
  include infrastructure
  include logrotate::nginx_json
  include logstash::app
  include mongodb::app
  include monit::app
  include nginx
  include openx
  include php5::app
  include subversion::app
}

Maybe this will clear up the problem.

Cheers,
David

David Jarosch

unread,
Jan 16, 2014, 10:09:59 AM1/16/14
to puppet...@googlegroups.com
Sorry,

but I'm a little bit pissed off. It seem's that this problem is caused by my keyboard and some kind of keyboard char coding/interpreting or something. This char ' was somehow interpreted different then in the Pro Puppet 2nd edition book which also look's exactly the same! I've copied this character ( ' ) from the book and pasted it in my manifest and voila, it worked!

Sorry for wasting your time, but this is ridiculous and time wasting for me too :(

Cheers,
David

jcbollinger

unread,
Jan 16, 2014, 11:59:58 AM1/16/14
to puppet...@googlegroups.com


On Thursday, January 16, 2014 9:09:59 AM UTC-6, David Jarosch wrote:
Sorry,

but I'm a little bit pissed off. It seem's that this problem is caused by my keyboard and some kind of keyboard char coding/interpreting or something. This char ' was somehow interpreted different then in the Pro Puppet 2nd edition book which also look's exactly the same! I've copied this character ( ' ) from the book and pasted it in my manifest and voila, it worked!


For what it's worth, the string delimiters in Puppet are the US-ASCII apostrophe and quotation mark, aka Unicode characters U+0027 and U+0022, respectively.  There are other characters that your system may render similarly to one of those, such as U+0060 (grave accent) U+00B4 (accute accent) and at least half a dozen others.  How similar any of those look to each other is a matter of the display font with which they are rendered.


John

Ramin K

unread,
Jan 16, 2014, 12:29:16 PM1/16/14
to puppet...@googlegroups.com
On 1/16/2014 3:16 AM, David Jarosch wrote:
> ### INSTALL NRPE PLUGINS WITHOUT ADDITIONAL RECOMMENDED PACKAGES
> exec { 'nagios-nrpe-plugin':
> unless => '/usr/bin/dpkg -l |grep nagios-nrpe-plugin',
> require => Class['nrpe::package'],
> command => '/usr/bin/apt-get install nagios-nrpe-plugin -y
> --no-install-recommends';
> }

I highly recommend turning off recommends globally on Debian based
systems. It's a bit more work in the beginning, but you remove a large
set of unknown behavior. With Puppet it is best to be explicit in
describing the final state of your machines and Recommends is a bit too
magical sometimes. It is a gray area based on conversations I've had
with other sys admins and it may make sense in your env.

IIRC is was installing nagios-plugins-all with recommends enabled that
caused our one and only Puppet related site outage. That package pulled
in Nagios which in turn needed apache-prefork which of course removed
apache-mpm-worker and brought the site down. Admittedly we would have
caught that if I hadn't been developing on a VM with Nagios already
installed.

Ramin
Reply all
Reply to author
Forward
0 new messages